CreateFlight(string departureLocation,
                     string landingLocation,
                     DateTime departureDateTime,
                     DateTime landingDatetime,
                     string planeType,
                     string planeUniqueId,
                     string pilotName,
                     int regularSeats,
                     int businessSeats)
        {
            if (ModelState.IsValid)
            {
                var currentFlight = FlightService.CreateFlight(departureLocation, landingLocation, departureDateTime, landingDatetime,
                                                               planeType, planeUniqueId, pilotName, regularSeats, businessSeats);

                if (currentFlight == -1)
                {
                    ViewBag.Message = "The departure and landing locations can't be the same!";
                    return(View());
                }
                if (currentFlight == -2)
                {
                    ViewBag.Message = "The departure datetime can't be ahead of the landing datetime!";
                    return(View());
                }
                if (currentFlight == -3)
                {
                    ViewBag.Message = "The plane UNIQUE id must be unique...";
                    return(View());
                }
            }
            return(this.RedirectToAction("ListFlights", "Flight"));
        }
        public async Task <IActionResult> Create([Bind("FlightId,Name,Aircraft,Date,Departure,DepartureTime,Arrival,ArrivalTime,Class,Capacity,Price,RemainSeats")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                await _flightService.CreateFlight(flight);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(flight));
        }
 public void Post([FromBody] FlightDTO flight)
 {
     if (ModelState.IsValid)
     {
         Response.StatusCode = 200;
         flightService.CreateFlight(flight);
     }
     else
     {
         Response.StatusCode = 400;
     }
 }
Ejemplo n.º 4
0
        public ActionResult CreateFlight(FlightViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Airports = _service.GetAllAirports();
                viewModel.Statuses = _service.GetAllStatuses();
                return(View("FlightForm", viewModel));
            }

            _service.CreateFlight(viewModel);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Post([FromBody] FlightDTO flight)
        {
            if (ModelState.IsValid)
            {
                //Response.StatusCode = 200;
                await flightService.CreateFlight(flight);

                return(Ok(flight));
            }
            else
            {
                return(BadRequest());
            }
        }
Ejemplo n.º 6
0
        public IActionResult Post([FromBody] FlightFromViewModel flightFromViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                Flight flight = mapper.Map <Flight>(flightFromViewModel);
                flightService.CreateFlight(flight, aircraftOptions);
                flightService.SaveFlight();
                return(CreatedAtAction("Get", "Flight", new { id = flight.FlightId }, flight));
            }
            catch (Exception ex)
            {
                logger.LogError(LoggingEvents.InsertItem,
                                ex,
                                "Error on inserting a new flight");
            }

            return(new StatusCodeResult(HttpStatusCodes.InternalServerError));
        }
Ejemplo n.º 7
0
        public IActionResult Create(CreateBindingModel input)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Flight/Create")); // do some error message
            }

            if (input.StartDestination == input.EndDestination)
            {
                return(Redirect("/Flight/DestinationsError")); // do some error message
            }

            // parse string to DateTime Format

            var takeOffTime = new DateTime();

            if (!DateTime.TryParse(input.TakeOffTime, out takeOffTime))
            {
                return(Redirect("/Flight/TimeError")); // do some error message
            }

            var arrivalTime = new DateTime();

            if (!DateTime.TryParse(input.ArrivalTime, out arrivalTime))
            {
                return(Redirect("/Flight/Create")); // do some error message
            }

            if (arrivalTime <= takeOffTime)         // check if flight times valid
            {
                return(Redirect("/Flight/Create")); // do some error message
            }

            var flight = new FlightServiceModel
            {
                StartDestination = input.StartDestination,
                EndDestination   = input.EndDestination,
                TakeOffTime      = takeOffTime,
                ArrivalTime      = arrivalTime,
                PlaneType        = input.PlaneType,
                PilotName        = input.PilotName
            };

            switch (input.PlaneType)
            {
            case PlaneType.SMALL:
                flight.FreeSeatsPassanger = 100;
                flight.FreeSeatsBussiness = 50;
                break;

            case PlaneType.MEDIUM:
                flight.FreeSeatsPassanger = 200;
                flight.FreeSeatsBussiness = 100;
                break;

            case PlaneType.LARGE:
                flight.FreeSeatsPassanger = 300;
                flight.FreeSeatsBussiness = 150;
                break;

            default:
                break;
            }

            flightService.CreateFlight(flight);

            return(Redirect("/Home/Index"));
        }