コード例 #1
0
 public IActionResult EditByFlight(Tour model)
 {
     if (HttpContext.Session.GetString("ID") == null)
     {
         return(RedirectToAction("Login", "Admin"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             if (model.TimeBegin.Date.CompareTo(model.TimeEnd.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(model));
             }
             else if (!model.TimeBegin.Date.Equals(tourRepository.getFlight(model.FlightID).DateGo.Date))
             {
                 ViewBag.listAllFlights     = tourRepository.listAllFlights();
                 ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                 ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                 ViewBag.listAllCities      = tourRepository.listAllCities();
                 ModelState.AddModelError(string.Empty, "Time Begin must be the same with Date Go of Flight | " + tourRepository.getFlight(model.FlightID).DateGo.Date);
                 return(View(model));
             }
             else if (!model.TimeEnd.Date.Equals(tourRepository.getFlight(model.FlightID).DateBack.Date))
             {
                 ViewBag.listAllFlights     = tourRepository.listAllFlights();
                 ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                 ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                 ViewBag.listAllCities      = tourRepository.listAllCities();
                 ModelState.AddModelError(string.Empty, "Time End must be the same with Date Back of Flight | " + tourRepository.getFlight(model.FlightID).DateBack.Date);
                 return(View(model));
             }
             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, "Time Begin must be the same with Group Up Time.");
                 return(View(model));
             }
             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(model));
             }
             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(model));
             }
             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(model));
             }
             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(model));
             }
             else if (model.MeetingTime.CompareTo(model.GroupUpTime) >= 0)
             {
                 ViewBag.listAllFlights     = tourRepository.listAllFlights();
                 ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                 ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                 ViewBag.listAllCities      = tourRepository.listAllCities();
                 ModelState.AddModelError(string.Empty, "Group Up Time must be bigger than Meeting Time.");
                 return(View(model));
             }
             else if (model.MeetingTime.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 Begin must be bigger than Meeting Time.");
                 return(View(model));
             }
             else if (model.TimeEnd.Date.CompareTo(model.MeetingTime.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 Meeting Time.");
                 return(View(model));
             }
             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, "Time End must be bigger than Group Up Time.");
                 return(View(model));
             }
             else
             {
                 // return view Index of Tour
                 tourRepository.Edit(model);
                 return(RedirectToAction("Index"));
             }
         }
         ViewBag.listAllFlights     = tourRepository.listAllFlights();
         ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
         ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
         ViewBag.listAllCities      = tourRepository.listAllCities();
         return(View(model));
     }
 }
コード例 #2
0
        public IActionResult CreatebyFlight(Tour model)
        {
            if (HttpContext.Session.GetString("ID") == null)
            {
                return(RedirectToAction("Login", "Admin"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    bool check = tourRepository.checkID(model.ID);
                    if (check)
                    {
                        if (model.TimeBegin.Date.CompareTo(model.TimeEnd.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(model));
                        }
                        //check date of tour with date of plane

                        else if (model.TimeBegin.Date.CompareTo(tourRepository.getFlight(model.FlightID).DateGo.Date) != 0)
                        {
                            ViewBag.listAllFlights     = tourRepository.listAllFlights();
                            ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                            ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                            ViewBag.listAllCities      = tourRepository.listAllCities();
                            ModelState.AddModelError(string.Empty, "Time Begin must be the same with Date Go of Flight | " + tourRepository.getFlight(model.FlightID).DateGo);
                            return(View(model));
                        }
                        else if (model.TimeEnd.Date.CompareTo(tourRepository.getFlight(model.FlightID).DateBack.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 the same with Date Back of Flight | " + tourRepository.getFlight(model.FlightID).DateBack);
                            return(View(model));
                        }
                        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, "Time Begin must be the same with Group Up Time.");
                            return(View(model));
                        }
                        //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.GroupUpTime.CompareTo(tourRepository.getFlight(model.FlightID).DateGo) >= 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 smaller than  Date Go of Flight | " + tourRepository.getFlight(model.FlightID).DateGo);
                            return(View(model));
                        }

                        //meeting of flight
                        else if (model.MeetingTime.GetValueOrDefault().CompareTo(model.GroupUpTime) >= 0)
                        {
                            ViewBag.listAllFlights     = tourRepository.listAllFlights();
                            ViewBag.listAllTourGuides  = tourRepository.listAllTourGuides();
                            ViewBag.listAllTravelTypes = tourRepository.listAllTravelTypes();
                            ViewBag.listAllCities      = tourRepository.listAllCities();
                            ModelState.AddModelError(string.Empty, "Group Up Time must be bigger than Meeting Time.");
                            return(View(model));
                        }
                        else if (model.MeetingTime.GetValueOrDefault().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 Begin must be bigger than Meeting Time.");
                            return(View(model));
                        }
                        else if (model.TimeEnd.Date.CompareTo(model.MeetingTime.GetValueOrDefault().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 Meeting Time.");
                            return(View(model));
                        }
                        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, "Time End must be bigger than Group Up Time.");
                            return(View(model));
                        }
                        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));
            }
        }