public ActionResult AddOrEdit(Employee emp) { try { if (emp.ImageUpload != null) { string fileName = Path.GetFileNameWithoutExtension(emp.ImageUpload.FileName); string extension = Path.GetExtension(emp.ImageUpload.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; emp.ImagePath = "~/AppFiles/Images/" + fileName; emp.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/Images/"), fileName)); } using (MvcProjectAliEntities db = new MvcProjectAliEntities()) { if (emp.EmployeeID == 0) { db.Employees.Add(emp); db.SaveChanges(); } else { db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); } } return(Json(new { success = true, html = GlobalClass.RenderRazorViewToString(this, "ViewAll", GetAllEmployee()), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
IEnumerable <Employee> GetAllEmployee() { using (MvcProjectAliEntities db = new MvcProjectAliEntities()) { return(db.Employees.ToList <Employee>()); } }
public ActionResult AddOrEdit(int id = 0) { Employee emp = new Employee(); if (id != 0) { using (MvcProjectAliEntities db = new MvcProjectAliEntities()) { emp = db.Employees.Where(x => x.EmployeeID == id).FirstOrDefault <Employee>(); } } return(View(emp)); }
public ActionResult Delete(int id) { try { using (MvcProjectAliEntities db = new MvcProjectAliEntities()) { 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", GetAllEmployee()), message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ReporterController() { _context = new MvcProjectAliEntities(); }