예제 #1
0
 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"));
 }
예제 #2
0
 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"));
 }