Beispiel #1
0
        public async Task <ActionResult> Create(FlightCreateViewModel model)
        {
            var createOperation = await _flightService.CreateFlightAsync(model.ToDto());

            if (createOperation.Success)
            {
                Session["Create"] = new AlertViewModel(createOperation.Message, AlertType.Success);

                return(RedirectToAction("Index", "Home"));
            }

            return(new HttpOperationStatusResult(createOperation));
        }
        public async Task <IActionResult> Post([FromBody] CreateFlightRequest request)
        {
            if (request == null)
            {
                throw new Exception("Request if f*****g null");
            }

            var flight = new Flight
            {
                Departure = DateTime.ParseExact(request.Departure, "dd-MM-yyyy HH:mm:ss", CultureInfo.InvariantCulture),
                FromId    = request.FromId,
                From      = await _countryService.GetCountryByIdAsync(request.FromId),
                ToId      = request.ToId,
                To        = await _countryService.GetCountryByIdAsync(request.ToId)
            };

            await _flightService.CreateFlightAsync(flight);

            var url = String.Format(
                "{0}://{1}{2}",
                HttpContext.Request.Scheme,
                HttpContext.Request.Host.ToUriComponent(),
                ApiRoutes.Flight.Get.Replace("{id}", flight.Id.ToString())
                );

            var response = new FlightResponse
            {
                Id        = flight.Id,
                Departure = flight.Departure,
                From      = new CountryResponse
                {
                    Id   = flight.From.Id,
                    Name = flight.From.Name
                },
                To = new CountryResponse
                {
                    Id   = flight.To.Id,
                    Name = flight.To.Name
                }
            };

            return(Created(url, response));
        }
Beispiel #3
0
        public async Task <IActionResult> CreateFlight([FromBody] UpdateFlightRequest updateFlightRequest)
        {
            var flight = await _flService.CreateFlightAsync(updateFlightRequest);

            return(Ok(new { status = 200, data = flight, message = "Flight successfully created" }));
        }