public IActionResult CreatebyCar(Tour model)
 {
     if (HttpContext.Session.GetString("ID") == null)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         //check validation
         if (ModelState.IsValid)
         {
             //check duplicate
             bool check = tourRepository.checkID(model.ID);
             if (check)
             {
                 //check Date of tour
                 if (model.TimeEnd.Date.CompareTo(model.TimeBegin.Date) > 0)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Time End must be bigger than Time Begin.");
                     return(View());
                 }
                 else if (model.TimeBegin.Date.CompareTo(model.GroupUpTime.Date) != 0)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Group Time must be must be the same with Time Begin.");
                     return(View());
                 }
                 else if (model.TimeEnd.Date.CompareTo(model.GroupUpTime.Date) <= 0)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Group Time must be must be the same with Time End.");
                     return(View());
                 }
                 // check price of tour
                 else
                 if (model.PriceForKid > model.PriceForAdult)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Price For Adult must be bigger than Price For Kid.");
                     return(View());
                 }
                 else
                 if (model.PriceForBaby > model.PriceForAdult)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Price For Adult must be bigger than Price For Bady.");
                     return(View());
                 }
                 else
                 if (model.PriceForBaby > model.PriceForKid)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Price For Kid must be bigger than Price For Bady.");
                     return(View());
                 }
                 else if (model.SeatsRemaining.CompareTo(model.TotalSeats) >= 0)
                 {
                     ViewBag.listAllFlights     = tourRepository.listAllFlights();
                     ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                     ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                     ViewBag.listAllCities      = tourRepository.listAllCities();
                     ModelState.AddModelError(string.Empty, "Total Seats must be must be the same with Seat Remaining.");
                     return(View());
                 }
                 else
                 {
                     tourRepository.addTour(model);
                     return(RedirectToAction("Index"));
                 }
             }
             else
             {
                 ViewBag.listAllFlights     = tourRepository.listAllFlights();
                 ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                 ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                 ViewBag.listAllCities      = tourRepository.listAllCities();
                 ModelState.AddModelError(string.Empty, "This ID already exists.");
                 return(View());
             }
         }
         ViewBag.listAllFlights     = tourRepository.listAllFlights();
         ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
         ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
         ViewBag.listAllCities      = tourRepository.listAllCities();
         return(View(model));
     }
 }