public ActionResult Delete(int id) { using (var context = new HospitalDirectoryContext()) { var hospital = context.Hospitals.Single(h => h.Id == id); context.Hospitals.Remove(hospital); context.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public ActionResult Save(Hospital hospital) { using (var context = new HospitalDirectoryContext()) { if (hospital.Id == 0) { hospital.CreatedOn = DateTime.Now; context.Hospitals.Add(hospital); } else { var hospitalInDb = context.Hospitals.Single(h => h.Id == hospital.Id); hospitalInDb.Name = hospital.Name; hospitalInDb.Street = hospital.Street; hospitalInDb.City = hospital.City; hospitalInDb.State = hospital.State; hospitalInDb.ZipCode = hospital.ZipCode; hospitalInDb.LastModified = DateTime.Now; } context.SaveChanges(); } return(RedirectToAction("Index", "Home")); }