public async Task <FlightResponse> AddFlight(FlightAddParameter flight, int airlineId) { try { var temp = await repo.AddFlight(flight, airlineId); if (temp.Success) { await unitOfWork.CompleteAsync(); } return(temp); } catch { return(new FlightResponse("Something went wrong. Please, try again later.")); } }
public async Task <IActionResult> AddFlight(FlightAddParameter flight) { var user = await adminService.GetAdminAsync(User.Identity.Name); if (user == null) { return(BadRequest(new { Message = "User does not exist" })); } var ret = await service.AddFlight(flight, user.AirlineID); if (ret.Success) { return(Ok(mapper.Map <FlightResource>(ret.Resource))); } else { return(BadRequest(new { Message = ret.Message })); } }
public async Task <FlightResponse> AddFlight(FlightAddParameter flight, int airlineId) { var temp = await context.Airlines.Include(i => i.Flights).Include(i => i.Airplanes).FirstOrDefaultAsync(i => i.Id == airlineId); if (temp != null) { var tempFlight = new Flight(); tempFlight.StartLocation = flight.StartLocation; tempFlight.EndLocation = flight.EndLocation; tempFlight.EndDate = flight.EndDate; tempFlight.FlightClass = flight.FlightClass; tempFlight.StartDate = flight.StartDate; tempFlight.IsRoundTrip = flight.IsRoundTrip; tempFlight.Distance = flight.Distance; tempFlight.LoadInCabin = flight.LoadInCabin; tempFlight.WeightPricings = flight.WeightPricings; tempFlight.PaidExtras = flight.Extras; if (flight.IsRoundTrip) { tempFlight.StartDateBack = flight.StartDateBack; tempFlight.EndDateBack = flight.EndDateBack; } tempFlight.Price = flight.Price; var tempAirplane = new Airplane(); tempAirplane.Rows = flight.Airplane.Rows; tempAirplane.Columns = flight.Airplane.Columns; tempFlight.Airplane = tempAirplane; foreach (var a in flight.StopsLocations) { tempFlight.StopsLocations.Add(a); } temp.Flights.Add(tempFlight); temp.Airplanes.Add(tempFlight.Airplane); return(new FlightResponse(tempFlight)); } return(new FlightResponse("Airline does not exist.")); }