public ActionResult Create(Flight flight) { try { if (ModelState.IsValid) { flight.Flight_id = Guid.NewGuid().ToString(); var DepartureCoord = _flightService.GetCoordinate(flight.Departure); var DestinationCoord = _flightService.GetCoordinate(flight.Destination); var Distance = DistanceCalculService.CalculDistance(DepartureCoord[0], DepartureCoord[1], DestinationCoord[0], DestinationCoord[1]); flight.Distance = (decimal?)Distance / 1000; flight.FuelConsumption = (decimal?)FuelCalculService.FuelCalculation(Distance / 1000); _flightService.CreateFlight(flight); //ViewBag.Departure = _flightService.GetAllAirportNames(); return(RedirectToAction("Index")); } return(View(flight)); } catch { return(View()); } }
public IActionResult CreateFlight(Flight flight) { flight.Arrival = DateTime.Parse(flight.Arrival.ToString()); flight.Departure = DateTime.Parse(flight.Departure.ToString()); var newFlight = _flightServices.CreateFlight(flight); return(CreatedAtRoute("GetFlight", new { newFlight.Id }, newFlight)); }
public async Task <IActionResult> CreateFlightPost(CreateFlightArgs newFlight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdFlight = await _flightServices.CreateFlight(newFlight); return(RedirectToAction("index")); }