CRUD operation using AngularJS and WebAPI in ASP.NET WebForm

CRUD operation using AngularJS and WebAPI in ASP.NET WebForm

In this Post We Will Explain About is CRUD operation using AngularJS and WebAPI in ASP.NET WebForm With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to crud operation in angularjs with web api Example

In this post we will show you Best way to implement crud operations in mvc 5 using web api with angularjs, hear for CRUD operation using AngularJS and WebAPI in ASP.NET WebForm with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.




Make Team ASP.NET WebAPI

Define CustomerApp and Factory

var app = angular.module('teamApp', []);
        var url = 'api/teams/'; 
    app.factory('teamFactory', function ($http) {
            return {
                getTeam: function () {
                    return $http.get(url);
                },
                addTeam: function (team) {
                    return $http.post(url, team);
                },
                deleteTeam: function (team) {
                    return $http.delete(url + team.teamID);
                },
                updateTeam: function (team) {
                    return $http.put(url + team.Id, team);
                }
            };
        });

TeamController

app.controller('TeamController', function PostsController($scope, teamFactory) {
            $scope.indianTeams = [];
            $scope.progressing = true;
            $scope.addnwmode = false;
  
            $scope.toggleTeam = function () {
                this.team.editTeam = !this.team.editTeam;
            };
            $scope.toggleAddTeam = function () {
                $scope.addnwmode = !$scope.addnwmode;
            };
            $scope.save = function () {
                $scope.progressing = true;
                var tm = this.team;
                teamFactory.updateTeam(tm).success(function (data) {
                    alert("Team Saved Successfully!!");
                    tm.editTeam = false;
                    $scope.progressing = false;
                }).error(function (data) {
                    $scope.error = "An some Error has occured while Saving team! " + data.ExceptionMessage;
                    $scope.progressing = false;
  
                });
            };
  
            // add Team
            $scope.add = function () {
                $scope.progressing = true;
                teamFactory.addTeam(this.newteam).success(function (data) {
                    alert("Added Successfully!!");
                    $scope.addnwmode = false;
                    $scope.indianTeams.push(data);
                    $scope.progressing = false;
                }).error(function (data) {
                    $scope.error = "An Error has occured while Adding team! " + data.ExceptionMessage;
                    $scope.progressing = false;
  
                });
            };
            // delete Team
            $scope.delTeam = function () {
                $scope.progressing = true;
                var currentTeam = this.team;
                teamFactory.deleteTeam(currentTeam).success(function (data) {
                    alert("Deleted Successfully!!");
                    $.each($scope.indianTeams, function (i) {
                        if ($scope.indianTeams[i].teamID === currentTeam.teamID) {
                            $scope.indianTeams.splice(i, 1);
                            return false;
                        }
                    });
                    $scope.progressing = false;
                }).error(function (data) {
                    $scope.error = "An Error has occured while Saving team! " + data.ExceptionMessage;
                    $scope.progressing = false;
  
                });
            };
  
            //get all teams
            teamFactory.getTeam().success(function (data) {
                $scope.indianTeams = data;
                $scope.progressing = false;
            })
            .error(function (data) {
                $scope.error = "An Error has occured while progressing posts! " + data.ExceptionMessage;
                $scope.progressing = false;
            });
  
        });

Full Page Code:(index.html)

<!DOCTYPE html>
<html data-ng-app="teamApp">
<head>
    <title>Team App | Live24u.com</title>
/1.0.6/angular.min.js
jquery/1.8.2/jquery.min.js
css/bootstrap.css
</head>
<body>  
    <div data-ng-controller="TeamController" class="container">
        <h2>teams</h2>
        <strong class="error">{{ error }}</strong>
        <div id="liveDiv" data-ng-show="progressing">
            <img src="Images/482.gif" class="ajax-loader" />
        </div>
        <p data-ng-hide="addnwmode"><a data-ng-click="toggleAddTeam()" href="javascript:;" class="btn btn-success">Add New</a></p>
        <form name="addTeam" data-ng-show="addnwmode" style="width: 600px; margin: 0px auto;">
            <label>Name:</label><input type="text" data-ng-model="newteam.Name" required />
            <label>Email:</label><input type="email" data-ng-model="newteam.Email" required />
            <br />          
            <span class="error" data-ng-show="addTeam.$error.email">Invalid Email format!</span>
            <br />
            <input type="submit" value="Add" data-ng-click="add()" data-ng-disabled="!addTeam.$valid" class="btn btn-success" />
            <input type="button" value="Cancel" data-ng-click="toggleAddTeam()" class="btn btn-success" />
            <br />
            <br />
        </form>
        <table class="table table-bordered table-hover" style="width: 900px">
            <tr>
                <th>#</th>
                <th>Team Name</th>
                <th>Team Email</th>
                <th></th>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="text" data-ng-model="query.Name" /></td>
                <td>
                    <input type="text" data-ng-model="query.Email" /></td>
                <td></td>
            </tr>
  
            <tr data-ng-repeat="team in indianTeams | filter:query">
                <td><strong data-ng-hide="team.editTeam">{{ team.teamID }}</strong></td>
                <td>
                    <p data-ng-hide="team.editTeam">{{ team.Name }}</p>
                    <p data-ng-show="team.editTeam">
                        <input type="text" data-ng-model="team.Name" />
                    </p>
                </td>
                <td>
                    <p data-ng-hide="team.editTeam">{{ team.Email }}</p>
                    <input data-ng-show="team.editTeam" type="text" data-ng-model="team.Email" /></td>
                <td>
                    <p data-ng-hide="team.editTeam"><a data-ng-click="toggleTeam(team)" href="javascript:;">Edit</a> | <a data-ng-click="delTeam(team)" href="javascript:;">Delete</a></p>
                    <p data-ng-show="team.editTeam"><a data-ng-click="save(team)" href="javascript:;">Save</a> | <a data-ng-click="toggleTeam(team)" href="javascript:;">Cancel</a></p>
                </td>
            </tr>
        </table>
        <hr />
    </div>
   <script src="app.js"></script>
     <style>
        #liveDiv { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1000; background-color: #c30000; opacity: .8; }
        .ajax-loader { position: absolute; left: 48%; top: 48%; margin-left: -25px; /* -1 * image width / 2 */ margin-top: -25px; /* -1 * image height / 2 */ display: block; }
          
    </style>
</body>
</html>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Also Read :   File handling READ AND WRITE TEXT FILE IN ASP.NET C#, VB





Example

I hope you have Got What is ASP.NET Web API application with Angularjs Forms and Bootstrap And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.