Beispiel #1
0
        public ActionResult Create([Bind(Include = "DepartureAirportID,DestinationAirportID,AircraftID")] FlightToDisplay flightInput)
        {
            if (ModelState.IsValid)
            {
                var res = flightService.AddFlight(flightInput)
                          ?? throw new ArgumentNullException("res");

                switch (res.Status)
                {
                case AddResultStatus.SameAirportsChosen:
                    //The airports chosen are the same, retry
                    ModelState.AddModelError("", "Please choose different airports");
                    break;

                case AddResultStatus.AlreadyExists:
                    //Flight exists in the DB, retry
                    ModelState.AddModelError("", "The entered flight already exists, please choose another one");
                    break;

                case AddResultStatus.Success:
                    //New entry successfully added
                    return(RedirectToAction("Index"));

                default:
                    //Internal Error
                    return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Unexpected Internal Error: " + res.Info));
                }
            }

            ViewBag.SelectableAirports  = flightService.Airports;
            ViewBag.SelectableAircrafts = flightService.Aircrafts;
            return(View(flightInput));
        }
Beispiel #2
0
        public void AddFlight_When_correct_data_Then_count_equal_1()
        {
            //assign
            FlightDTO flight = new FlightDTO()
            {
                ArrivalTime    = new DateTime(2018, 7, 14, 5, 30, 0),
                DeparturePlace = "Odessa, Ukraine",
                Destination    = "Vilnius, Lithuania",
                DepartureTime  = new DateTime(2018, 7, 13, 23, 20, 0)
            };

            //act
            flightService.AddFlight(flight);

            //assert
            Assert.That(Flights.Count == 1);
        }
        [HttpPost] //POST localhost/Flights
        public async Task <IActionResult> AddFlight(AddFlightDto newFlight)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(await _flightService.AddFlight(newFlight)));
        }
Beispiel #4
0
 public JsonResult Post([FromBody] FlightDTO flight)
 {
     try
     {
         return(Json(flightService.AddFlight(flight)));
     }
     catch (System.Exception ex)
     {
         HttpContext.Response.StatusCode = 400;
         return(Json(ex.Message));
     }
 }
Beispiel #5
0
 public async Task <IActionResult> Add(Models.PostFlightModel addFlight)
 {
     try
     {
         await _service.AddFlight(addFlight);
     }
     catch (Exception ex)
     {
         _logger.LogError($"Add {ex.Message}");
     }
     return(RedirectToAction("Index", "Flight"));
 }
        public async Task <IActionResult> AddFlight(FlightAddParameter flight)
        {
            var user = await adminService.GetAdminAsync(User.Identity.Name);

            if (user == null)
            {
                return(BadRequest(new { Message = "User does not exist" }));
            }

            var ret = await service.AddFlight(flight, user.AirlineID);

            if (ret.Success)
            {
                return(Ok(mapper.Map <FlightResource>(ret.Resource)));
            }
            else
            {
                return(BadRequest(new { Message = ret.Message }));
            }
        }
        private bool AddFlight(FlightModel flightModel)
        {
            var editWindow = new EditFlightWindow();
            var ctx        = (EditFlightViewModel)editWindow.DataContext;

            ctx.Flight    = flightModel;
            ctx.Routes    = _routeService.GetAllRoutes();
            ctx.Airplanes = _airplaneService.GetAllAirplanes();
            if (editWindow.ShowDialog() != true)
            {
                return(false);
            }

            var errs = GetModelErrors(ctx.Flight);

            if (errs != string.Empty)
            {
                ShowError(errs, "Error! Saving cancelled. ");
                return(false);
            }

            _flightService.AddFlight(flightModel);
            return(true);
        }
Beispiel #8
0
        public async Task <IActionResult> AddFlight(FlightSearchDTO flight)
        {
            var result = await flightService.AddFlight(User, flight);

            return(this.FromResult(result));
        }