public ActionResult Insert(Hotel hotel) { if (ModelState.IsValid) { hotelRepository.Save(hotel); return RedirectToAction("List"); } return View(hotel); }
public void Save(Hotel hotel) { if ((hotel.Id == null) || (hotel.Id == Guid.Empty)) { hotel.Id = Guid.NewGuid(); Context.Hotels.Add(hotel); } else { var existing_hotel = Context.Hotels.First(x => x.Id == hotel.Id); if (existing_hotel != null) { existing_hotel.Name = hotel.Name; //Add more mapping } } Context.SaveChanges(); }