public ActionResult Edit(Employee employee) { try { // TODO: Add update logic here if(ModelState.IsValid) { SampleDBContext db = new SampleDBContext(); Employee employeeFromDB = db.Employees.Single(x => x.Id == employee.Id); employeeFromDB.FullName = employee.FullName; employeeFromDB.Gender = employee.Gender; employeeFromDB.Age = employee.Age; employeeFromDB.HireDate = employee.HireDate; employeeFromDB.Salary = employee.Salary; employeeFromDB.PersonalWebSite = employee.PersonalWebSite; UpdateModel(employeeFromDB); db.SaveChanges(); return RedirectToAction("Details", new { id = employee.Id }); } return View(employee); } catch { return View(); } }
public ActionResult Create(Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return RedirectToAction("Index"); } return View(employee); }
public ActionResult Edit(Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(employee); }