public ActionResult Delete(int? id) { EmployeeContext dbContext = new EmployeeContext(); if (id != null) { Employee employee = dbContext.Employees.SingleOrDefault(e => e.EmployeeId == id); if (employee != null) { dbContext.Employees.Remove(employee); } dbContext.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult CreatePost() { ActionResult action = View(); Employee employee = new Employee(); TryUpdateModel<Employee>(employee); if (ModelState.IsValid) { EmployeeContext dbContext = new EmployeeContext(); dbContext.Employees.Add(employee); dbContext.SaveChanges(); action = RedirectToAction("Index"); } return action; }
public ActionResult EditPost() { ActionResult action = View(); Employee employee = new Employee(); TryUpdateModel<Employee>(employee); if (ModelState.IsValid) { EmployeeContext dbContext = new EmployeeContext(); Employee currentDetails = dbContext.Employees.SingleOrDefault(x => x.EmployeeId == employee.EmployeeId); // Name property is black listed if (currentDetails != null) { currentDetails.Gender = employee.Gender; currentDetails.DateOfBirth = employee.DateOfBirth; currentDetails.City = employee.City; dbContext.SaveChanges(); } action = RedirectToAction("Index"); } return action; }