public ActionResult CreateTicketsInFlight(CreateTicketsInFlight inFlight) { //if (ModelState.IsValid)// На фронтовій частині не відбувається валідація полів!!! if (inFlight != null) { string info; if (flightBusinessLogic.CreateFlight(inFlight)) { info = "Рейс Створено"; return(RedirectToAction("InfoAndErrors", "Admin", new { info })); } else { info = "Помилка заповнення форми"; return(RedirectToAction("InfoAndErrors", "Admin", new { info })); } } else { return(HttpNotFound()); } }
public bool CreateFlight(CreateTicketsInFlight flight) { //Підрахунок тривалості польоту TimeSpan span = new TimeSpan(); span = flight.Flight.DateTimeDestination - flight.Flight.DateTimeOrigin; if (flight.Flight.DateTimeOrigin < DateTime.Now || flight.Flight.DateTimeDestination < DateTime.Now || span.TotalHours > 24 || flight.Flight.DestinationCity == flight.Flight.OriginCity || flight.Price < 1 || flight.Count < 1 || flight.Flight.FlightNumber < 1 || string.IsNullOrEmpty(flight.Flight.Airline) || flight.Flight.FlightNumber < 999 || flight.Flight.FlightNumber > 9999) { return(false); } List <Ticket> tickets = new List <Ticket>(); for (int i = 0; i < flight.Count; i++) { Ticket ticket = new Ticket { Clas = flight.ToClass.ToString(), Price = flight.Price, Status = null, Flight = flight.Flight }; tickets.Add(ticket); } flight.Flight.Tickets.AddRange(tickets); flight.Flight.FlightDuration = span; flightsContext.Flight.Add(flight.Flight); flightsContext.SaveChanges(); return(true); }