Tuesday, 29 August 2017

calling service $resource from controller

var axiommodule = angular.module("appaxiom", ['ngResource']);
axiommodule.controller("appcontroller", function (axiomservice) {
    var vm = this;
    vm.hello = "hellow angular";
    vm.name = axiomservice.GetStudent();
    var student = { Name: 'new', Age: '34', Semester: '4th' };
    axiomservice.StudentResource().get({ teacherid: 1 },
        function (response)
        {
            alert(response.Name);
        });
    //axiomservice.StudentResource.update({id:1},function (response) {
    //    alert('deleted');
    //});
   // alert(vm.student);
    //.
    //                        then(function (response) {
    //                            alert('');
    //                        });
   
});
axiommodule.service("axiomservice", function ($http,$resource) {
    this.GetStudent = function () {
        return "hello ! world angular you are very cruel";
    };
    this.StudentResource = function () {
        return $resource('api/Student', {id:'@id',teacherid:'@teacherid'});
         
    };
});



=========================factory way of calling resource===================
var mod = angular.module('appmodf', ['ngResource']);
mod.controller('gridController', function (gridFactory) {
    var vm = this;  
    gridFactory.studentrepo.query(successCallBack,errorCallBack);
    function successCallBack(data)
    {

            vm.students=data;
        }
        function errorCallBack(error)
        {
            vm.error=error;
        }
   
    });

mod.factory('gridFactory', function ($resource) {
    var service = { studentrepo: $resource(' http://localhost:6074/api/Student/:id/:teacherid', { id: '@id', teacherid: '@teacherid' }) };
    return service;
});

angular $resource

find is not a default action for $resource. The defaults are:
{ 'get':    {method:'GET'},
  'save':   {method:'POST'},
  'query':  {method:'GET', isArray:true},
  'remove': {method:'DELETE'},
  'delete': {method:'DELETE'} };
You will have to create/specify the find action. You are currently creating/specifying a chargeaction. Perhaps this is what you meant to use?
If you want to use find, here is the fix:
.factory('testResource1', function ($resource) {
     return $resource('/SoloAngularTable/TestMethod3', { id: '@id' }, {
         charge: { method: 'POST' },
         find: { method: 'POST' } // Added `find` action
     });
});
If you meant to use charge, here is the fix:
.controller('ContentPlaceHolder1Controller', function ($scope, $http, testResource1) {                            
     testResource1.charge({ id: 123 }, function (data) {                            
          alert('success');
     });
});

Monday, 28 August 2017

owin oaut using bearer token jwt token

http://www.c-sharpcorner.com/uploadfile/ff2f08/token-based-authentication-using-asp-net-web-api-owin-and-i/

connection string for local db

    <add name="OwinAuthDbContext" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\OwinAuthDbContext.mdf;Initial Catalog=OwinAuthDbContext;Integrated Security=True" providerName="System.Data.SqlClient" />

Saturday, 26 August 2017

Thursday, 24 August 2017

configure ui-route for angularjs

http://plnkr.co/edit/IzimSVsstarlFviAm7S7?p=preview

myApp.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
    $locationProvider.hashPrefix('');
//to remove the # from the url
    $locationProvider.html5Mode(true);
    $urlRouterProvider.otherwise('/home/data');
 
    $stateProvider

        // HOME STATES AND NESTED VIEWS ========================================
     
     .state('homedata', {
         url: '/home/data',
         title:'student data',
         templateUrl: '/home/GridDataView'   // corresponds to the action method in the home controller returns the view

     })
    .state('NgGridDemo', {
        url: '/NgGrid/data',
        title:'NgGrid Demo',
        templateUrl: '/nggrid/NgGridDemo'

    })

Sunday, 20 August 2017

simple crud using angular js

<!DOCTYPE html>
<html ng-app="myApp">
<head >
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <script src="~/Scripts/angular.min.js"></script>
    <script src="~/Scripts/angular-route.js"></script>

</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home", new { area = "" }, null)</li>
                    <li>@Html.ActionLink("API", "Index", "Help", new { area = "" }, null)</li>
                </ul>
            </div>
        </div>
    </div>
    <div class="container body-content" ng-controller="GreetingController">
        @RenderBody()

        <input type="text" ng-model="listitem" />
        <button value="add item" ng-click="additem()">add item</button>
        <hr />
        {{greeting}}-<a ng-click="showdata()">show list</a>
        <ul>
            <li ng-repeat="item in myWelcome" ng-click="getitembyid(item)" >{{item}}--<a ng-click="removeitem(item)">remove item</a></li>
        </ul>
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
    <script>

        var myApp = angular.module('myApp', []);

        myApp.controller('GreetingController', function ($scope,$http) {
         
            $scope.showdata = function showdata() {
                $http.get(
                   'api/values/'
               ).then(function mySuccess(response) {
                   $scope.myWelcome = response.data;
               }, function myError(response) {
                   $scope.myWelcome = response.statusText;
               });
            };
            $scope.getitembyid = function getitembyid(item) {
                $http.get(
                 'api/values/' + 1
             ).then(function mySuccess(response) {
                 //$scope.myWelcome = response.data;
                 //alert(response.data);
             }, function myError(response) {
                 $scope.myWelcome = response.statusText;
             });

            };

            $scope.removeitem = function removeitem(item) {
             
                var index = $scope.myWelcome.indexOf(item);
                $scope.myWelcome.splice(index, 1);
            }

            $scope.additem = function additem() {
             
                $scope.myWelcome.push($scope.listitem);
                $scope.listitem = "";
            }
           
        }
     
        );
    </script>
</body>
</html>

Tuesday, 15 August 2017

SOLID principles explained in a well business domain example

http://www.reflectivesoftware.com/2015/08/10/a-solid-refactoring-exercise-part-1-dependency-inversion-principle/

Monday, 14 August 2017