public void AddNewFlight(FlightModel flight) { var date = flight.TakeOfDate.ToString().Split(' '); _flightService.AddNewFlight(new Flight { FlightCode = flight.FlightCode, FlightName = flight.FlightName, Source = flight.Source, Destination = flight.Destination, TakeOfDate = date[0], AirportName = flight.AirportName, Time = flight.TakeOfDate.Value.TimeOfDay.ToString(), Price = (double)flight.Price, Description = flight.Description, }); }
public IActionResult AddNewFlight([FromBody] FlightViewModel flight) { if (flight == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } try { flight.Id = _flightService.AddNewFlight(flight.ToEntity()); } catch (Exception ex) { _logger.LogCritical("Could not add new flight details.", ex); return(StatusCode(500, "A Problem happend with handling your request.")); } return(CreatedAtRoute("GetFlight", new { flightId = flight.Id })); }
public ActionResult NewFlight(FlightViewModel model) { _flightService.AddNewFlight(model); return(RedirectToAction("ViewFlights")); }