public IActionResult AddConvenient(ConvenientHotel model) { if (HttpContext.Session.GetString("ID") == null) { return(RedirectToAction("Login", "Admin")); } else { if (ModelState.IsValid) { //get HotelID int hotelID = Convert.ToInt32(model.HotelID); //get convenientID int convenientID = Convert.ToInt32(model.ConvenientID); // check convenientID and HotelID in HotelConvenient table if (hotelRepository.checkConvenientIDInConvenientHotel(convenientID, hotelID)) { //forward HotelID to View ViewBag.hotelID = model.HotelID; // execute addConvenient method hotelRepository.AddConvenient(model); //notification ModelState.AddModelError(string.Empty, "Success."); return(View(hotelRepository.getAllConvenients)); } else { ViewBag.hotelID = model.HotelID; ModelState.AddModelError(string.Empty, "This Convenient already exists."); return(View(hotelRepository.getAllConvenients)); } } ViewBag.hotelID = model.HotelID; return(View(hotelRepository.getAllConvenients)); } }
public void AddConvenient(ConvenientHotel _ConvenientHotel) { db.tbl_ConvenientHotel.Add(_ConvenientHotel); db.SaveChanges(); }