public void Post([FromBody] FlightDTO flight) { if (ModelState.IsValid) { service.Create(flight); } }
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()); }
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)); }
public async Task <IActionResult> Create([FromBody] FlightDto flight) { if (ModelState.IsValid) { await _service.Create(flight); return(Ok(flight)); } else { return(new BadRequestObjectResult(ModelState)); } }
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)); } }
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)); }
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)); }
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")); }
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)); }
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")); }
public async Task <ActionResult> CreateFlight([FromBody] FlightModel model) { await _flightService.Create(model); return(Ok()); }
public IActionResult AddFlight(FlightViewModel model) { flightService.Create(model); return(View()); }