Пример #1
0
 public void Post([FromBody] FlightDTO flight)
 {
     if (ModelState.IsValid)
     {
         service.Create(flight);
     }
 }
Пример #2
0
        public IActionResult Create(FlightViewModel flight)
        {
            _logger.LogInformation(flight.ToString());
            var result = _flightService.Create(flight);

            if (result.Result.Status)
            {
                return(RedirectToAction("Index"));
            }
            return(RedirectToAction("Error"));
        }
        public async Task <ActionResult <FlightViewModel> > Post(FlightViewModel flight)
        {
            var response = await _flightService.Create(flight.ToModel());

            if (response != BusinessLogic.Enums.StatusCode.Created)
            {
                _logger.LogError($"Flight not created.");
            }

            return(response == BusinessLogic.Enums.StatusCode.Created
                ? (ActionResult <FlightViewModel>)Ok()
                : Conflict());
        }
Пример #4
0
        public IActionResult Post([FromBody] FlightDTO value)
        {
            var validationResult = _flightModelValidator.Validate(value);

            if (!validationResult.IsValid)
            {
                throw new BadRequestException(validationResult.Errors);
            }

            var entity = _flightService.Create(value);

            return(Json(entity));
        }
Пример #5
0
        public async Task <IActionResult> Create([FromBody] FlightDto flight)
        {
            if (ModelState.IsValid)
            {
                await _service.Create(flight);

                return(Ok(flight));
            }
            else
            {
                return(new BadRequestObjectResult(ModelState));
            }
        }
Пример #6
0
 public async Task <IActionResult> Post([FromBody] FlightDto value)
 {
     try
     {
         return(Ok(await service.Create(value)));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
 public IActionResult Post([FromBody] FlightDto value)
 {
     try
     {
         service.Create(value);
         return(Ok());
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Пример #8
0
        public async Task <IActionResult> Create([Bind("Id,DepartureId,DestinationId,DateTime,StopNumber,SeatNumber")] FlightDto flight)
        {
            if (ModelState.IsValid)
            {
                long id = await _service.Create(flight);

                if (id == 0)
                {
                    return(Conflict());
                }

                await _signalrHub.Clients.All.SendAsync("LoadFlights");

                return(RedirectToAction(nameof(Index)));
            }
            return(View(flight));
        }
Пример #9
0
        public IActionResult Post([FromBody] FlightDto flight)
        {
            if (flight == null)
            {
                ModelState.AddModelError("", "Не указаны данные для полёта");
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            service.Create(flight);

            return(Created("api/Flights", flight));
        }
        public async Task <IActionResult> Post([FromBody] FlightDTO modelDTO)
        {
            if (modelDTO == null)
            {
                ModelState.AddModelError("", "Flight structure is wrong!!!");
                return(BadRequest(ModelState));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await service.Create(modelDTO);

            return(Created("api/Flights", modelDTO));
        }
Пример #11
0
        public IActionResult Create(CreateBindingModel input)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Flight/Create"));
            }

            var departureTime = new DateTime();

            if (!DateTime.TryParse(input.DepartureTime, out departureTime))
            {
                return(Redirect("/Flight/Create"));
            }

            var arrivalTime = new DateTime();

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

            if (arrivalTime < departureTime)
            {
                return(Redirect("/Flight/Create"));
            }

            var flight = new FlightServiceModel
            {
                From                = input.From,
                To                  = input.To,
                ArrivalTime         = arrivalTime,
                DepartureTime       = departureTime,
                FreePassengersSeats = input.FreePassengersSeats,
                FreeBusinessSeats   = input.FreeBusinessSeats,
                PlaneNumber         = input.PlaneNumber,
                PlaneType           = input.PlaneType,
                Image               = input.Image,
                PilotName           = input.PilotName
            };

            flightService.Create(flight);

            return(Redirect("/Home/Index"));
        }
Пример #12
0
        public IActionResult Post([FromBody] FlightDto flightDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { Type = "ValidationError", ErrorMessage = "Required fields is empty" }));
            }

            FlightDto resultDto;

            try
            {
                resultDto = flightService.Create(flightDto);
            }
            catch (Exception ex)
            {
                return(BadRequest(new { ErrorType = ex.GetType().Name, ex.Message }));
            }

            return(Ok(resultDto));
        }
Пример #13
0
        public async Task <IActionResult> Create(FlightInputModel model)
        {
            if (model.LandingTime < DateTime.Now)
            {
                ModelState.AddModelError(nameof(FlightInputModel.LandingTime), "Landing time must be in the future!");
            }
            if (model.TakeOffTime < DateTime.Now)
            {
                ModelState.AddModelError(nameof(FlightInputModel.LandingTime), "Take off time must be in the future!");
            }
            if (model.LandingTime < model.TakeOffTime)
            {
                ModelState.AddModelError(nameof(FlightInputModel.TakeOffTime), "Take off time must be before landing time!");
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await flightService.Create(model);

            return(Redirect("/Flight/All"));
        }
Пример #14
0
        public async Task <ActionResult> CreateFlight([FromBody] FlightModel model)
        {
            await _flightService.Create(model);

            return(Ok());
        }
Пример #15
0
        public IActionResult AddFlight(FlightViewModel model)
        {
            flightService.Create(model);

            return(View());
        }