public IActionResult AddHotels(TourHotel model) { if (HttpContext.Session.GetString("ID") == null) { return(RedirectToAction("Login", "Admin")); } else { if (ModelState.IsValid) { int hotelID = Convert.ToInt32(model.HotelID); string tourID = model.TourID.ToString(); if (tourRepository.checkHotelID(tourID, hotelID)) { tourRepository.AddHotel(model); return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "This Hotel already exists."); //ViewBag.Error = "This Hotel already exists."; //If the system encounters an error, immediately go to the Addhotel page. //return Redirect("https://localhost:44361/Tour/AddHotel/"+tourID); TempData["Error"] = "This Hotel already exists."; return(RedirectToAction("AddHotel", "Tour", new { Id = tourID })); } } //If the system encounters an error, immediately go to the Addhotel page. return(Redirect("https://localhost:44361/Tour/AddHotel/" + model.TourID)); } }
public ActionResult Index() { //Display Active Home ViewBag.isActive = UtilContants.HOME_NAV; TourModel model = new TourModel(); var tour = model.listTourHot(); var hotel = model.listHotel(); var listComboBoxToPlace = model.listComboBoxToPlace(); var listComboBoxFromPlace = model.listComboBoxFromPlace(); TourHotel listContainer = new TourHotel(); listContainer.Tour = tour; listContainer.Hotel = hotel; listContainer.listComboBoxFromPlace = listComboBoxFromPlace; listContainer.listComboBoxToPlace = listComboBoxToPlace; return(View(listContainer)); }
public void AddHotel(TourHotel _TourHotel) { db.tbl_TourHotel.Add(_TourHotel); db.SaveChanges(); }