Introduction
Starting with the database

Download the requred js and css files from below given links
Be familiar with the things before proceeding
Start with the Code




After that go to the controller folder and Create EmployeeController
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using BootstrapAngularMvc.Models;
  7. namespace BootstrapAngularMvc.Controllers
  8. {
  9. public class EmployeeController : Controller
  10. {
  11. public ActionResult Employee()
  12. {
  13. return View();
  14. }
  15. //For getting the all records from database.
  16. public JsonResult getAll()
  17. {
  18. using (SahilEntities dataContext = new SahilEntities())
  19. {
  20. var employeeList = (from E in dataContext.Employees
  21. join dep in dataContext.Departments on E.DepartmentID equals dep.Id
  22. join dsg in dataContext.Designations on E.DesignationID equals dsg.Id
  23. orderby E.Id
  24. select new
  25. {
  26. E.Id,
  27. E.name,
  28. E.DOB,
  29. E.Gender,
  30. E.Email,
  31. E.Mobile,
  32. E.Address,
  33. E.JoiningDate,
  34. dep.DepartmentName,
  35. E.DepartmentID,
  36. dsg.DesignationName,
  37. E.DesignationID
  38. }).ToList();
  39. var JsonResult = Json(employeeList, JsonRequestBehavior.AllowGet);
  40. JsonResult.MaxJsonLength = int.MaxValue;
  41. return JsonResult;
  42. }
  43. }
  44. }
  45. }
Change application startup controller and action
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using System.Web.Routing;
  7. namespace BootstrapAngularMvc
  8. {
  9. public class RouteConfig
  10. {
  11. public static void RegisterRoutes(RouteCollection routes)
  12. {
  13. routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  14. routes.MapRoute(
  15. name: "Default",
  16. url: "{controller}/{action}/{id}",
  17. defaults: new { controller = "Employee", action = "Employee", id = UrlParameter.Optional }
  18. );
  19. }
  20. }
  21. }
Add Module.js,Controller.js,Service.js in content folder
  1. var app = angular.module("myApp", []);
  1. app.controller("myCntrl", function ($scope, myService) {
  2. GetAllEmployees();
  3. //For sorting according to columns
  4. $scope.sort = function (keyname) {
  5. $scope.sortKey = keyname;
  6. $scope.reverse = !$scope.reverse;
  7. }
  8. //To Get All Records
  9. function GetAllEmployees() {
  10. var getData = myService.getEmployees();
  11. getData.then(function (emp) {
  12. $scope.employees = emp.data;
  13. }, function (emp) {
  14. alert("Records gathering failed!");
  15. });
  16. }
  17. });
  • In Service.js write the given code.
  • myService is the name of the service registers with the myApp module.
  • $http is passed as parameter. $http serves the purpose for ajax call to the server.
  • In this service getEmployees function is used to call the getAll server method by providing url.
  • This method returns the response to the controller.
  1. app.service("myService", function ($http) {
  2. //get All Employee
  3. this.getEmployees = function () {
  4. return $http.get("/Employee/getAll");
  5. };
  6. });
Add view from the controller
  1. <dir-pagination-controls
  2. max-size="10"
  3. direction-links="true"
  4. boundary-links="true">
  5. </dir-pagination-controls>
  1. @{
  2. ViewBag.Title = "Employee";
  3. }
  4. <html ng-app="myApp">
  5. <head>
  6. <title></title>
  7. <script src="~/Content/angular1.2.18.min.js"></script>
  8. <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
  9. <script src="~/Content/bootstrap.min.js"></script>
  10. <script src="~/Content/Module.js"></script>
  11. <script src="~/Content/Controller.js"></script>
  12. <script src="~/Content/Service.js"></script>
  13. <script src="~/Content/dirPagination.js"></script>
  14. <style>
  15. table {
  16. border-collapse: collapse;
  17. border-spacing: 0;
  18. width: 100%;
  19. border: 1px solid #ddd;
  20. }
  21. th, td {
  22. border: none;
  23. text-align: left;
  24. padding: 8px;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="container" ng-controller="myCntrl">
  30. <input type="button" class="btn btn-success btn-lg" ng-click="AddEmployeeDiv();" value=" Add Employee" style="margin-left: 15px;" data-toggle="modal" data-target="#myModal" />
  31. <hr style="width: 550px;" />
  32. <form class="form-inline">
  33. <div class="form-group">
  34. <b>Search : </b>
  35. <input type="text" placeholder="Search" class="form-control" ng-model="search" />
  36. </div>
  37. </form>
  38. <br />
  39. <table cellpadding="12" class="table table-bordered table-hover table-striped">
  40. <tr class="success">
  41. <th style="cursor: pointer;" ng-click="sort('id')"><b>Employee ID</b> <span class="glyphicon sort-icon" ng-show="sortKey=='id'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  42. <th style="cursor: pointer;" ng-click="sort('Name')"><b>Name</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Name'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  43. <th style="cursor: pointer; width: 100px;" ng-click="sort('DOB')"><b>DOB</b> <span class="glyphicon sort-icon" ng-show="sortKey=='DOB'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  44. <th style="cursor: pointer;" ng-click="sort('Gender')"><b>Gender</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Gender'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  45. <th style="cursor: pointer;" ng-click="sort('Email')"><b>Email</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Email'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  46. <th style="cursor: pointer;" ng-click="sort('Mobile')"><b>Mobile</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Mobile'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  47. <th style="cursor: pointer;" ng-click="sort('Address')"><b>Address</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Address'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  48. <th style="cursor: pointer; width: 100px;" ng-click="sort('JoiningDate')"><b>Joining Date</b> <span class="glyphicon sort-icon" ng-show="sortKey=='JoiningDate'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  49. <th style="cursor: pointer;" ng-click="sort('Department')"><b>Department</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Department'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  50. <th style="cursor: pointer;" ng-click="sort('Designation')"><b>Designation</b> <span class="glyphicon sort-icon" ng-show="sortKey=='Designation'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span></th>
  51. <th><b>Actions</b></th>
  52. </tr>
  53. <tr dir-paginate="employee in employees|orderBy:sortKey:reverse|filter:search|itemsPerPage:10" ng-model="search">
  54. <td>{{employee.Id}}
  55. </td>
  56. <td>{{employee.name}}
  57. </td>
  58. <td style="width: 100px;">{{employee.DOB |date:'dd-MM-yyyy'}}
  59. </td>
  60. <td>{{employee.Gender}}
  61. </td>
  62. <td>{{employee.Email}}
  63. </td>
  64. <td>{{employee.Mobile}}
  65. </td>
  66. <td>{{employee.Address}}
  67. </td>
  68. <td style="width: 100px;">{{employee.JoiningDate}}
  69. </td>
  70. <td>{{employee.DepartmentName}}
  71. </td>
  72. <td>{{employee.DesignationName}}
  73. </td>
  74. <td>
  75. <a class="btn btn-Primary btn-sm" ng-click="editEmployee(employee)" href="">Edit</a>
  76. </td>
  77. </tr>
  78. <b style="color: #5bc0de;">Total Records </b>: <b>{{employees.length}} </b>
  79. </table>
  80. <dir-pagination-controls
  81. max-size="10"
  82. direction-links="true"
  83. boundary-links="true">
  84. </dir-pagination-controls>
  85. <div id="myModal" class="modal fade" role="dialog">
  86. <div class="modal-dialog">
  87. <!-- Modal content-->
  88. <div class="modal-content">
  89. <div class="modal-header">
  90. <button type="button" class="close" data-dismiss="modal">×</button>
  91. <h4 class="modal-title">{{Action}} Employee Details</h4>
  92. </div>
  93. <div class="modal-body">
  94. <div class="form-horizontal">
  95. <div class="form-group">
  96. <div class="row">
  97. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  98. <b>Name :</b>
  99. </div>
  100. <div class="col-md-8 col-sm-8">
  101. <input type="text" class="form-control" data-modal="modal" ng-model="employeeName" placeholder="Employee's Name" ng-required="true" />
  102. </div>
  103. </div>
  104. </div>
  105. <div class="form-group">
  106. <div class="row">
  107. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  108. <b>DOB :</b>
  109. </div>
  110. <div class="col-md-8 col-sm-8">
  111. <div class="input-group date">
  112. <input class="form-control" type="text" id="datetimepicker" value="1990/01/01">
  113. <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. <div class="form-group">
  119. <div class="row">
  120. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  121. <b>Gender:</b>
  122. </div>
  123. <div class="col-md-8 col-sm-8" ng-required="true">
  124. <input type="radio" title="Male" data-modal="modal" ng-model="employeeGender" value="Male" />
  125. Male
  126. <input type="radio" title="Female" data-modal="modal" ng-model="employeeGender" value="Female" />
  127. Female
  128. </div>
  129. f
  130. </div>
  131. </div>
  132. <div class="form-group">
  133. <div class="row">
  134. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  135. <b>Email:</b>
  136. </div>
  137. <div class="col-md-8 col-sm-8">
  138. <input type="email" class="form-control" data-modal="modal" ng-model="employeeEmail" placeholder="Employee's Email" ng-required="true" />
  139. </div>
  140. </div>
  141. </div>
  142. <div class="form-group">
  143. <div class="row">
  144. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  145. <b>Mobile:</b>
  146. </div>
  147. <div class="col-md-8 col-sm-8">
  148. <input type="text" class="form-control" data-modal="modal" ng-model="employeeMobile" placeholder="Employee's Mobile" ng-required="true" />
  149. </div>
  150. </div>
  151. </div>
  152. <div class="form-group">
  153. <div class="row">
  154. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  155. <b>Address:</b>
  156. </div>
  157. <div class="col-md-8 col-sm-8">
  158. <input type="text" class="form-control" data-modal="modal" ng-model="employeeAddress" placeholder="Employee's Address" ng-required="true" />
  159. </div>
  160. </div>
  161. </div>
  162. <div class="form-group">
  163. <div class="row">
  164. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  165. <b>Joining Date:</b>
  166. </div>
  167. <div class="col-md-8 col-sm-8">
  168. <input type="date" class="form-control" data-modal="modal" ng-model="employeeJoiningDate" ng-required="true" />
  169. </div>
  170. </div>
  171. </div>
  172. <div class="form-group">
  173. <div class="row">
  174. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  175. <b>Department:</b>
  176. </div>
  177. <div class="col-md-8 col-sm-8">
  178. <select id="ddlDepartment" class="form-control" data-modal="modal" ng-model="employeeDepartment" ng-options="dep.Id as dep.DepartmentName for dep in departments" ng-required="true">
  179. <option value="" disabled>--Select Department--</option>
  180. @* <option data-ng-repeat="dep in departments" value="{{dep.Id}}">{{dep.DepartmentName}}</option>*@
  181. </select>
  182. </div>
  183. </div>
  184. </div>
  185. <div class="form-group">
  186. <div class="row">
  187. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;">
  188. <b>Designation:</b>
  189. </div>
  190. <div class="col-md-8 col-sm-8">
  191. <select id="ddlDesignation" class="form-control" data-modal="modal" ng-model="employeeDesignation" ng-options="dsg.Id as dsg.DesignationName for dsg in designations" ng-required="true">
  192. <option value="" disabled>--Select Designation--</option> f/span>
  193. </select>
  194. </div>
  195. </div>
  196. </div>
  197. <div class="form-group">
  198. <div class="row">
  199. <div class="col-md-2 col-sm-2" style="margin-left: 20px; color: #5bc0de;"></div>
  200. <div class="col-md-8 col-sm-8">
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. <div class="modal-footer">
  206. <input type="button" class="btnAdd btn btn-success" value="Save" ng-click="AddUpdateEmployee()" data-dismiss="modal" />
  207. <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. <div id="alertModal" class="modal fade">
  214. <div class="modal-dialog">
  215. <div class="modal-content">
  216. <!-- dialog body -->
  217. <div class="modal-body">
  218. <button type="button" class="close" data-dismiss="modal">×</button>
  219. {{msg}}
  220. </div>
  221. <!-- dialog buttons -->
  222. <div class="modal-footer">
  223. <button type="button" ng-click="alertmsg()" class="btn btn-primary">OK</button>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. </div>
  229. </body>
  230. </html>
Starts with paging
  1. var app = angular.module("myApp", ['angularUtils.directives.dirPagination']);
Apply CSS and Scripts file
  1. public static class BundleConfig
  2. {
  3. public static void RegisterBundles(BundleCollection bundles)
  4. {
  5. RegisterStyleBundles(bundles);
  6. RegisterJavascriptBundles(bundles);
  7. }
  8. private static void RegisterStyleBundles(BundleCollection bundles)
  9. {
  10. bundles.Add(new StyleBundle("~/css")
  11. .Include("~/Content/bootstrap.css")
  12. .Include("~/Content/site.css"));
  13. }
  14. private static void RegisterJavascriptBundles(BundleCollection bundles)
  15. {
  16. bundles.Add(new ScriptBundle("~/js")
  17. .Include("~/Scripts/jquery-{version}.js")
  18. .Include("~/Scripts/jquery-ui-{version}.js")
  19. .Include("~/Scripts/bootstrap.js"));
  20. }
  21. }
Starts writing code for CRUD operations
  • In the EmployeeController, AddEmployee method passed with Employee class is used to store the data in database.
  • This method returns the string message to the service.
  1. <-- Employee record insertion code -->
  2. public string AddEmployee(Employee Emp)
  3. {
  4. if (Emp != null)
  5. {
  6. using (SahilEntities dataContext = new SahilEntities())
  7. {
  8. Employee employee = new Employee();
  9. employee.name = Emp.name;
  10. employee.DOB = Convert.ToDateTime(Emp.DOB).ToString("yyyy/MM/dd");
  11. employee.Gender = Emp.Gender;
  12. employee.Email = Emp.Email;
  13. employee.Mobile = Emp.Mobile;
  14. employee.Address = Emp.Address;
  15. employee.JoiningDate = Convert.ToDateTime(Emp.JoiningDate).ToString("yyyy/MM/dd");
  16. employee.DepartmentID = Emp.DepartmentID;
  17. employee.DesignationID = Emp.DesignationID;
  18. dataContext.Employees.Add(employee);
  19. dataContext.SaveChanges();
  20. return "Employee added Successfully";
  21. }
  22. }
  23. else
  24. {
  25. return "Addition of Employee unsucessfull !";
  26. }
  27. }
  1. <-- Get Employee by ID -->
  2. public JsonResult getEmployeeByNo(string EmpNo)
  3. {
  4. try
  5. {
  6. using (SahilEntities dataContext = new SahilEntities())
  7. {
  8. int no = Convert.ToInt32(EmpNo);
  9. var employeeList = dataContext.Employees.Find(no);
  10. return Json(employeeList, JsonRequestBehavior.AllowGet);
  11. }
  12. }
  13. catch (Exception exp)
  14. {
  15. return Json("Error in getting record !", JsonRequestBehavior.AllowGet);
  16. }
  17. }
  1. <-- Employee record updation code -->
  2. public string UpdateEmployee(Employee Emp)
  3. {
  4. if (Emp != null)
  5. {
  6. using (SahilEntities dataContext = new SahilEntities())
  7. {
  8. int no = Convert.ToInt32(Emp.Id);
  9. var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault();
  10. employeeList.name = Emp.name;
  11. employeeList.DOB = Convert.ToDateTime(Emp.DOB).ToString("yyyy/MM/dd");
  12. employeeList.Gender = Emp.Gender;
  13. employeeList.Email = Emp.Email;
  14. employeeList.Mobile = Emp.Mobile;
  15. employeeList.Address = Emp.Address;
  16. employeeList.JoiningDate = Convert.ToDateTime(Emp.JoiningDate).ToString("yyyy/MM/dd");
  17. employeeList.DepartmentID = Emp.DepartmentID;
  18. employeeList.DesignationID = Emp.DesignationID;
  19. dataContext.SaveChanges();
  20. return "Employee Updated Successfully";
  21. }
  22. }
  23. else
  24. {
  25. return "Invalid Employee";
  26. }
  27. }
  1. <-- Bind dropdownlist of designations -->
  2. public JsonResult GetDesignations()
  3. {
  4. using (SahilEntities context = new SahilEntities())
  5. {
  6. var desg = context.Designations.ToList();
  7. return Json(desg, JsonRequestBehavior.AllowGet);
  8. }
  9. }
  1. <-- Bind dropdownlist of departments -->
  2. public JsonResult GetDepartments()
  3. {
  4. using (SahilEntities data = new SahilEntities())
  5. {
  6. var deps = data.Departments.ToList();
  7. return Json(deps, JsonRequestBehavior.AllowGet);
  8. }
  9. }
Write code in Controller.js i.e. given below
  • AddEmployeeDiv function basically calls the modal popup for adding employee information but some other functions also called on calling this function.
  • ClearFields function called in the same function are used to empty the html controls.
  • GetDepartments() and GetDesignations() calls the function for binding drop downs simultaneously.
  • alertmsg() close the alert popup that display the messages.
  • GetDesignations() calls the GetDesignations() method from the service to bind the dropdown.
  • The response returned in the data is passed to the $scope to access on the page.
  • GetDepartments() works same like GetDesignations.
  • editEmployee() function calls the function from the service and returned data is filled in every $scope to show on the page.
  • AddUpdateEmployee() insert and update the employee based on the action name.Here all the data from the $scopes is stored in the object named employee containing fields with the same name as in the database.
  • After this based on action name save or update function from the service is called.
  • In $scope.Action we store Add if we create new employee and store Edit if we edit the employee.
  • At last ClearFields() function clear the HTML controls after saving or updating the records.
  • Add the given code in Controller.js file.
  1. <-- This is used to open popup for adding record. -->
  2. $scope.AddEmployeeDiv = function () {
  3. ClearFields();
  4. $scope.Action = "Add";
  5. GetDepartments();
  6. GetDesignations();
  7. }
  8. <-- Alert Popup for save ,update messages . -->
  9. $scope.alertmsg = function () {
  10. $("#alertModal").modal('hide');
  11. };
  12. <-- Bind dropdownlist for designation. -->
  13. function GetDesignations() {
  14. var desg = myService.GetDesignations();
  15. desg.then(function (dsg) {
  16. $scope.designations = dsg.data;
  17. }, function (dsg) {
  18. $("#alertModal").modal('show');
  19. $scope.msg = "Error in filling designation drop down !";
  20. });
  21. }
  22. <-- Bind dropdownlist for department. -->
  23. function GetDepartments() {
  24. var departments = myService.GetDepartment();
  25. departments.then(function (dep) {
  26. $scope.departments = dep.data;
  27. }, function (dep) {
  28. $("#alertModal").modal('show');
  29. $scope.msg = "Error in filling departments drop down !";
  30. });
  31. }
  32. <-- Get the employee By ID. -->
  33. $scope.editEmployee = function (employee) {
  34. debugger;
  35. GetDesignations();
  36. GetDepartments();
  37. var getData = myService.getEmployee(employee.Id);
  38. getData.then(function (emp) {
  39. $scope.employee = emp.data;
  40. $scope.employeeId = employee.Id;
  41. $scope.employeeName = employee.name;
  42. $scope.employeeDOB = new Date(employee.DOB);
  43. $scope.employeeGender = employee.Gender;
  44. $scope.employeeEmail = employee.Email;
  45. $scope.employeeMobile = employee.Mobile;
  46. $scope.employeeAddress = employee.Address;
  47. $scope.employeeJoiningDate = employee.JoiningDate;
  48. $scope.employeeDepartment = employee.DepartmentID;
  49. $scope.employeeDesignation = employee.DesignationID;
  50. $scope.Action = "Edit";
  51. $("#myModal").modal('show');
  52. },
  53. function (msg) {
  54. $("#alertModal").modal('show');
  55. $scope.msg = msg.data;
  56. });
  57. }
  58. <-- Insertion and updation code. -->
  59. $scope.AddUpdateEmployee = function () {
  60. var Employee = {
  61. Name: $scope.employeeName,
  62. DOB: $scope.employeeDOB,
  63. Gender: $scope.employeeGender,
  64. Email: $scope.employeeEmail,
  65. Mobile: $scope.employeeMobile,
  66. Address: $scope.employeeAddress,
  67. JoiningDate: $scope.employeeJoiningDate,
  68. DepartmentID: $scope.employeeDepartment,
  69. DesignationID: $scope.employeeDesignation
  70. };
  71. var getAction = $scope.Action;
  72. if (getAction == "Edit") {
  73. Employee.Id = $scope.employeeId;
  74. var getData = myService.updateEmp(Employee);
  75. getData.then(function (msg) {
  76. GetAllEmployee();
  77. ClearFields();
  78. $("#alertModal").modal('show');
  79. $scope.msg = msg.data;
  80. }, function (msg) {
  81. $("#alertModal").modal('show');
  82. $scope.msg = msg.data;
  83. });
  84. }
  85. else {
  86. var getData = myService.AddEmp(Employee);
  87. getData.then(function (msg) {
  88. GetAllEmployee();
  89. $("#alertModal").modal('show');
  90. $scope.msg = msg.data;
  91. ClearFields();
  92. }, function (msg) {
  93. $("#alertModal").modal('show');
  94. $scope.msg = msg.data;
  95. });
  96. }
  97. debugger;
  98. GetAllEmployee();
  99. $scope.refresh();
  100. }
  101. <-- Clear fields after save -->
  102. function ClearFields() {
  103. $scope.employeeId = "";
  104. $scope.employeeName = "";
  105. $scope.employeeDOB = "";
  106. $scope.employeeGender = "";
  107. $scope.employeeEmail = "";
  108. $scope.employeeMobile = "";
  109. $scope.employeeAddress = "";
  110. $scope.employeeJoiningDate = "";
  111. $scope.employeeDepartment = "";
  112. $scope.employeeDesignation = "";
  113. }
Start writing code in Service.js
  • AddEmp function calls the server method AddEmployee from EmployeeController by providing url,method,dataType,data.The response returned from the server is returned to the controller.js.
  • getEmployee function calls the getEmployeeByNo method from the Employee controller by providing url and employeeID as parameter.Again the response is passed to the controller.js.
  • updateEmp calls the UpdateEmployee method from the server and returns the response in same manner.
  • getDesignation calls GetDesignations from server to get the complete list of designations and fill the drop down list with that data.
  • Same process is with the getDepartments.
  • Add this code in the service.js file.
  1. <-- Calls Add Employee method on server -->
  2. this.AddEmp = function (employee) {
  3. var response = $http({
  4. method: "post",
  5. url: "/Employee/AddEmployee",
  6. data: JSON.stringify(employee),
  7. dataType: "json"
  8. });
  9. return response;
  10. }
  11. <-- Calls get Employee By Id method on server -->
  12. this.getEmployee = function (employeeID) {
  13. var response = $http({
  14. method: "post",
  15. url: "/Employee/getEmployeeByNo",
  16. params: {
  17. id: JSON.stringify(employeeID)
  18. }
  19. });
  20. return response;
  21. }
  22. <--Calls the update method on server -->
  23. this.updateEmp = function (employee) {
  24. var response = $http({
  25. method: "post",
  26. url: "/Employee/UpdateEmployee",
  27. data: JSON.stringify(employee),
  28. dataType: "json"
  29. });
  30. return response;
  31. }
  32. <-- Calls the method on server for Designation dropdownlist -->
  33. this.GetDesignations = function () {
  34. return $http.get("/Employee/GetDesignations");
  35. };
  36. <-- Calls the method on server for Department dropdownlist -->
  37. this.GetDepartment = function () {
  38. return $http.get("/Employee/GetDepartments");
  39. };
That's it with the code.
Read more articles on AngularJS: