public bool AddFlightOrder(FlightOrder flightOrder) { int rowsEffected = -1; using (var context = new DataContext(DataContext.ops.dbOptions)) { User user = context.User.Where(theUser => theUser.UserId == flightOrder.User.UserId).SingleOrDefault(); Flight flight = context.Flight.Where(theFlight => theFlight.FlightId == flightOrder.Flight.FlightId).SingleOrDefault(); FlightLuggage flightLuggage = context.FlightLuggage.Where(theFlightLuggage => theFlightLuggage.FlightLuggageId == flightOrder.FlightLuggage.FlightLuggageId).SingleOrDefault(); Seat seat = context.Seat.Where(theSeat => theSeat.SeatId == flightOrder.Seat.SeatId).SingleOrDefault(); FlightTicket flightTicket = context.FlightTicket.Where(theFlightTicket => theFlightTicket.FlightTicketId == flightOrder.FlightTicket.FlightTicketId).SingleOrDefault(); flightOrder.User = user; flightOrder.Flight = flight; flightOrder.FlightLuggage = flightLuggage; flightOrder.Seat = seat; flightOrder.FlightTicket = flightTicket; context.FlightOrder.Add(flightOrder); rowsEffected = context.SaveChanges(); if (rowsEffected > 0) { return(true); } } return(false); }
public FlightLuggage GetFlightLuggage(int id) { FlightLuggage flightLuggage = new FlightLuggage(); using (var context = new DataContext(DataContext.ops.dbOptions)) { flightLuggage = context.FlightLuggage.Where(theLuggage => theLuggage.FlightLuggageId == id).SingleOrDefault(); } return(flightLuggage); }
public async Task <IActionResult> AddLuggage(FlightLuggage lugg) { try { await context.Luggages.AddAsync(lugg); await context.SaveChangesAsync(); return(Ok()); } catch (Exception e) { return(NoContent()); } }
public bool AddFlightLuggage(FlightLuggage flightLuggage) { int rowsEffected = -1; using (var context = new DataContext(DataContext.ops.dbOptions)) { context.Add(flightLuggage); try { rowsEffected = context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.StackTrace); } } return(rowsEffected > 0 ? true : false); }
public async Task <IActionResult> ChangeLuggageForCompany(FlightLuggage lugg) { try { FlightLuggage fl = await context.Luggages.SingleOrDefaultAsync(x => x.IdCompany == lugg.IdCompany); fl.CarryOnPrice = lugg.CarryOnPrice; fl.DuffelPrice = lugg.DuffelPrice; context.Luggages.Update(fl); await context.SaveChangesAsync(); return(Ok()); } catch (Exception e) { return(NoContent()); } }
public Holder <FlightLuggage> AddFlightLuggage(FlightLuggage flightLuggage) { List <FlightLuggage> flightLuggageList = _airlineDatabase.GetFlightLuggage(); if (flightLuggage.FlightLuggageType.GetType() == typeof(DBNull)) { return(CheckFlightLuggage(flightLuggage, 400, "Flight luggage must have type")); } foreach (FlightLuggage luggageInstance in flightLuggageList) { if (luggageInstance.FlightLuggageType == flightLuggage.FlightLuggageType) { return(CheckFlightLuggage(flightLuggage, 403, "Flight luggage with this type already exists")); } } if (_airlineDatabase.AddFlightLuggage(flightLuggage)) { return(CheckFlightLuggage(flightLuggage, 200, "")); } return(CheckFlightLuggage(flightLuggage, 500, "Unable to add flight luggage")); }
public Holder <FlightLuggage> AddFlightLuggage([FromBody] FlightLuggage flightLuggage) { return(_airlineBusiness.AddFlightLuggage(flightLuggage)); }
Holder <FlightLuggage> CheckFlightLuggage(FlightLuggage flightLuggage, int errorCode, string description) => errorCode == 200 ? Holder <FlightLuggage> .Success(flightLuggage) : Holder <FlightLuggage> .Fail(errorCode, description);