public override IAnswer execute() { Database.FlightRequest fr = new Database.FlightRequest (); List<Database.Flight> flights = fr.fetchFlightFromCodeAndStartDate (flight.Template.Code, flight.StartDate); if (flights.Count != 1) { return new AnswerAdd ("No (unique) flight with code " + flight.Template.Code + " at " + flight.StartDate); } int flightID = flights [0].ID; Database.SeatRequest sr = new Database.SeatRequest (); List<Database.Seat> seats = sr.fetchSeatFromFlightAndNumber (flightID, seat.Number); if (seats.Count != 1) { return new AnswerAdd("No (unique) seat with number " + seat.Number + " at flight with code " + flight.Template.Code + " at " + flight.StartDate); } int seatID = seats[0].ID; Database.SeatPrice sp = new Database.SeatPrice(seatID, flightID, price); try{ sp.insert(); } catch(Exception e){ return new AnswerAdd(e.Message); } return new AnswerAdd(); }
public override IAnswer execute() { Database.SeatPriceRequest spr = new Database.SeatPriceRequest (); Database.SeatRequest sr = new Database.SeatRequest (); Database.FlightRequest fr = new Database.FlightRequest (); List<Database.Flight> flights = fr.fetchFlightFromCodeAndStartDate (flight.Template.Code, flight.StartDate); if (flights.Count != 1) { throw new Exception ("No (unique) flight with code " + flight.Template.Code + " and start date " + flight.StartDate + " could be found"); } int flightID = flights [0].ID; List<Database.Seat> seats = sr.fetchSeatFromFlightAndNumber (flightID, seat.Number); if (seats.Count != 1) { throw new Exception ("No (unique) seat with number " + seat.Number + " is found on flight with code " + flight.Template.Code + " and start date " + flight.StartDate); } int seatID = seats [0].ID; List<Database.SeatPrice> seatPrices = spr.fetchSeatPriceFromSeatAndFlight (seatID, flightID); if (seatPrices.Count != 1) { throw new Exception("No (unique) seat price found for seat with number " + seat.Number + " is found on flight with code " + flight.Template.Code + " and start date " + flight.StartDate); } SeatPrice sp = new SeatPrice(seat, flight, seatPrices[0].price); return new AnswerGetSeatPrice(sp); }