public Models.Flight AddFlight(Models.Flight flight) { flight.Id = 0; var newFlight = _db.Flight.Add(flight); _db.SaveChanges(); return(newFlight.Entity); }
public async Task <ActionResult <Models.BookingError> > PostBooking(Models.Booking bM) { Console.WriteLine(bM); Flight f = _context.FlightSet.Find(bM.FlightNo); if (f == null) { return(new Models.BookingError(404, "The flight was not find, please try again")); } Models.Flight fM = f.ConvertToFlightM(); if (fM.AvailableSeats <= 0) { return(new Models.BookingError(99, "The selected flight is already full")); } if (fM.Date < DateTime.Now) { return(new Models.BookingError(36, "The selected flight is not available")); } var calculatedPrice = fM.GetPrice(); Console.WriteLine(calculatedPrice); if (!fM.GetPrice().Equals(bM.Price)) { return(new Models.BookingError(103, "The selected price does not match. Please retry the booking")); } Passenger p = new Passenger { Surname = bM.Surname, GivenName = bM.GivenName, Weight = bM.Weight }; _context.PassengerSet.Add(p); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { throw; } Booking b = new Booking { FlightNo = bM.FlightNo, PassengerID = p.PersonID, PricePaid = bM.Price }; _context.BookingSet.Add(b); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { throw; } return(new Models.BookingError(500, "The booking was successfully registered")); }
// GET: BookingsController/Create public ActionResult Create(Models.Flight f) { Models.Booking b = new Models.Booking(); b.FlightNo = f.FlightNo; b.Price = f.SeatPrice; return(View(b)); }
public async Task <IActionResult> Post([FromBody] Models.Flight nflight) { if (ModelState.IsValid) { var newFlight = await uow.Flights.Create(nflight).ConfigureAwait(false); return(Ok(newFlight)); } return(BadRequest()); }
public FlightVM(Models.Flight flight) { Id = flight.Id; Title = flight.Title; Source = flight.Source.ToString(); Destination = flight.Destination.ToString(); Date = flight.Date.ToPersianDateString(); Quantity = flight.Quantity; Price = 120000; }
public static EFCoreApp2020E.Flight ConvertToFlightEF(this Models.Flight f) { var refFlight = new EFCoreApp2020E.Flight(); refFlight.FlightNo = f.FlightNo; refFlight.Seats = f.Seats; refFlight.Date = f.Date; refFlight.Departure = f.Departure; refFlight.Destination = f.Destination; return(refFlight); }
public async Task <ActionResult <double> > GetFlightCurrentSalePrice(int id) { var flight = await _context.FlightSet.FindAsync(id); if (flight == null) { return(NotFound()); } Models.Flight fM = flight.ConvertToFlightM(); return(fM.GetPrice()); }
public async Task <IActionResult> Put(int id, [FromBody] Models.Flight nFlight) { if (ModelState.IsValid) { if (id == nFlight.FlightId) { await uow.Flights.Update(nFlight).ConfigureAwait(false); return(Ok()); } } return(BadRequest()); }
public static Models.Flight ConvertToFlightM(this EFCoreApp2020E.Flight f) { Models.Flight fM = new Models.Flight(); fM.FlightNo = f.FlightNo; fM.Date = f.Date; fM.Departure = f.Departure; fM.Destination = f.Destination; /** * @TODO Remove ? **/ fM.Seats = f.Seats; fM.AvailableSeats = (short)(f.Seats - f.BookingSet.Count); fM.SeatPrice = f.BasePrice; return(fM); }
public void Save(Models.Flight flight) { MySqlConnection conection = adapter.GetConection(); string sql = "INSERT INTO `flujoaereo`.`flight` (`Type`, `Origin`, `Destiny`, `Pist`, `DepartureDate`, `DepartureHour`, `ArrivalDate`, `ArrivalHour`, `FlightTime` , `Status`, `AirlineID`, `AirplaneID`, `PilotID`) VALUES ('" + flight.Type + "', '" + flight.Origin + "', '" + flight.Destiny + "', '" + flight.Pist + "', '" + flight.DepartureDate + "', '" + flight.DepartureHour + "', '" + flight.ArrivalDate + "', '" + flight.ArrivalHour + "', '" + flight.FlightTime + "', '" + flight.FlightStatus + "', '" + flight.AirlineID + "', '" + flight.AirplaneID + "', '" + flight.PilotID + "');"; try { MySqlCommand insertCommnad = new MySqlCommand(sql) { Connection = conection }; insertCommnad.ExecuteNonQuery(); insertCommnad.Connection.Close(); } catch (Exception e) { throw new InvalidOperationException(e.Message); } }
public ActionResult Reserve([FromRoute] int flightId, [FromBody] List <ViewModel.ReseveFlightVM> model) { ResponseModel <int> result = new ResponseModel <int>(); try { int userId = _userRepo.GetCurrentUserId(); Models.Flight flight = _flightRepo.GetFlightById(flightId); if (flight == null) { result.SetError("پرواز یافت نشد"); return(Ok(result)); } var reserveId = _flightRepo.ReserveFlight(userId, flightId, model); result.Data = reserveId; return(Ok(result)); } catch (System.Exception ex) { return(StatusCode(500)); } }
protected override bool FilterFlight(Models.Flight flight) { return(this._flightData.HomeAirport == flight.Origin); }
public void EditFlight(Models.Flight flight) { flightRepo.Update(flight); }
public void AddFlight(Models.Flight flight) { flightRepo.Create(flight); }