public ActionResult Create(HotelDetails hoteldetails) { //if (ModelState.IsValid) //{ // db.HotelDetails.Add(hoteldetails); // db.SaveChanges(); // return RedirectToAction("Index"); //} //return View(hoteldetails); using (BSSDbContext db = new BSSDbContext()) { HotelDetails Hotel = db.HotelDetails.FirstOrDefault(h => h.HotelName.ToLower() == hoteldetails.HotelName.ToLower()); // Check if Hotel already exists if (Hotel == null) { // Insert name into the profile table db.HotelDetails.Add(new HotelDetails { HotelName = hoteldetails.HotelName }); db.SaveChanges(); return RedirectToAction("Index"); } else { ModelState.AddModelError("HotelName", "Hotel Name already exists. Please enter a different Hotel Name."); } } return View(hoteldetails); }
public ActionResult Edit(HotelDetails hoteldetails) { if (ModelState.IsValid) { db.Entry(hoteldetails).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(hoteldetails); }