Пример #1
0
 IEnumerable <Employee> GetEmployees()
 {
     using (AjaxDemoEntities db = new AjaxDemoEntities())
     {
         return(db.Employees.ToList <Employee>());
     }
 }
Пример #2
0
 public JsonResult AddOrEdit(Employee emp)
 {
     using (AjaxDemoEntities db = new AjaxDemoEntities()) {
         db.Employees.Add(emp);
         db.SaveChanges();
     }
     //return RedirectToAction("ViewAll");
     return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetEmployees()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
 }
Пример #3
0
        public ActionResult AddOrEdit(int id = 0)
        {
            Employee emp = new Employee();

            if (id != 0)
            {
                using (AjaxDemoEntities db = new AjaxDemoEntities())
                {
                    emp = db.Employees.Where(x => x.EmployeeId == id).FirstOrDefault <Employee>();
                }
            }
            return(View(emp));
        }
Пример #4
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (AjaxDemoEntities db = new AjaxDemoEntities())
         {
             Employee emp = db.Employees.Where(x => x.EmployeeId == id).FirstOrDefault <Employee>();
             db.Employees.Remove(emp);
             db.SaveChanges();
         }
         return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetEmployees()), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
     }
 }