/// <summary> /// Get Employee With Id /// </summary> /// <param name="Id"></param> /// <returns></returns> public JsonResult Get_EmployeeById(string Id) { using (webAppDbEntities Obj = new webAppDbEntities()) { int EmpId = int.Parse(Id); return(Json(Obj.Menus.Find(EmpId), JsonRequestBehavior.AllowGet)); } }
/// <summary> /// /// Get All Employee /// </summary> /// <returns></returns> public JsonResult Get_AllEmployee() { using (webAppDbEntities Obj = new webAppDbEntities()) { List <Menu> Emp = Obj.Menus.ToList(); return(Json(Emp, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Insert New Employee /// </summary> /// <param name="Employe"></param> /// <returns></returns> public string Insert_Employee(Menu menu) { if (menu != null && ModelState.IsValid) { using (webAppDbEntities Obj = new webAppDbEntities()) { Obj.Menus.Add(menu); Obj.SaveChanges(); return("Menu Added Successfully"); } } else { return("Menu Not Inserted! Try Again"); } }
/// <summary> /// Update Employee Information /// </summary> /// <param name="Emp"></param> /// <returns></returns> public string Update_Employee(Menu menu) { if (menu != null && ModelState.IsValid) { using (webAppDbEntities Obj = new webAppDbEntities()) { var menu_ = Obj.Entry(menu); Menu EmpObj = Obj.Menus.Where(x => x.MenuId == menu.MenuId).FirstOrDefault(); EmpObj.MenuName = menu.MenuName; EmpObj.MenuIcon = menu.MenuIcon; EmpObj.Status = menu.Status; Obj.SaveChanges(); return("Menu Updated Successfully"); } } else { return("Menu Not Updated! Try Again"); } }
/// <summary> /// Delete Employee Information /// </summary> /// <param name="Emp"></param> /// <returns></returns> public string Delete_Employee(Menu menu) { if (menu != null) { using (webAppDbEntities Obj = new webAppDbEntities()) { var menu_ = Obj.Entry(menu); if (menu_.State == EntityState.Detached) { Obj.Menus.Attach(menu); Obj.Menus.Remove(menu); } Obj.SaveChanges(); return("Menu Deleted Successfully"); } } else { return("Employee Not Deleted! Try Again"); } }