Пример #1
0
        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));
            }
        }