using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication3.Models;
using System.Data;
namespace MvcApplication3.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult GetAll()
{
using (Database1Entities obj = new Database1Entities())
{
return Json(obj.EMPs.ToList(), JsonRequestBehavior.AllowGet);
}
}
public JsonResult GetById(int id)
{
using (Database1Entities obj = new Database1Entities())
{
return Json(obj.EMPs.Single(m => m.EID == id), JsonRequestBehavior.AllowGet);
}
}
public string Add(EMP emp)
{
using (Database1Entities obj = new Database1Entities())
{
obj.Entry(emp).State = EntityState.Added;
obj.SaveChanges();
return "Data Saved.";
}
}
public string Put(EMP emp)
{
using (Database1Entities obj = new Database1Entities())
{
EMP emp1 = obj.EMPs.Single(m => m.EID == emp.EID);
emp1.NAME = emp.NAME;
obj.Entry(emp1).State = EntityState.Modified;
obj.SaveChanges();
return "Data Updated.";
}
}
public string Delete(EMP emp)
{
using (Database1Entities obj = new Database1Entities())
{
EMP emp1 = obj.EMPs.Single(m => m.EID == emp.EID);
obj.Entry(emp1).State = EntityState.Deleted;
obj.SaveChanges();
return "Data Deleted.";
}
}
}
}
1. Module.js : write the following code in it.
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication3.Models;
using System.Data;
namespace MvcApplication3.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
public JsonResult GetAll()
{
using (Database1Entities obj = new Database1Entities())
{
return Json(obj.EMPs.ToList(), JsonRequestBehavior.AllowGet);
}
}
public JsonResult GetById(int id)
{
using (Database1Entities obj = new Database1Entities())
{
return Json(obj.EMPs.Single(m => m.EID == id), JsonRequestBehavior.AllowGet);
}
}
public string Add(EMP emp)
{
using (Database1Entities obj = new Database1Entities())
{
obj.Entry(emp).State = EntityState.Added;
obj.SaveChanges();
return "Data Saved.";
}
}
public string Put(EMP emp)
{
using (Database1Entities obj = new Database1Entities())
{
EMP emp1 = obj.EMPs.Single(m => m.EID == emp.EID);
emp1.NAME = emp.NAME;
obj.Entry(emp1).State = EntityState.Modified;
obj.SaveChanges();
return "Data Updated.";
}
}
public string Delete(EMP emp)
{
using (Database1Entities obj = new Database1Entities())
{
EMP emp1 = obj.EMPs.Single(m => m.EID == emp.EID);
obj.Entry(emp1).State = EntityState.Deleted;
obj.SaveChanges();
return "Data Deleted.";
}
}
}
}
1. Module.js : write the following code in it.
var app = angular.module( "myApp" ,[]); Service.js : Write the following code in it. app.service("angularService", function ($http) { Controller.js : Write the following code . app.controller("myCntrl", function ($scope, angularService) { |
No comments:
Post a Comment