// // GET: /Employee/ public ActionResult Details() { Employee employee = new Employee() { EmployeeId = 101, Name = "John", Gender = "Male", City = "London", }; return View(employee); }
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; }