public static string DisplayDetailsForSeatsInFlight(Flight flight) { StringBuilder builder = new StringBuilder(); using (var context = new ABS()) { // Gets the seats for a given flight. var query = context.Seats.Where(s => s.FlightId == flight.FlightId); // Foreach First Buisiness Economy. foreach (string name in Enum.GetNames(typeof(SeatClass))) { // Finds the section by SeatClass. var section = context.Sections.Where(m => m.SeatClassName == name).FirstOrDefault(); // Checks if the associated floght have such seatClass. var checker = query.Where(s => s.SectionId == section.SectionId).FirstOrDefault(); // If the flight does not have such seat class nothing more is appended. if (checker == null) { continue; } // Appends the name of the seat class and the seats. builder.Append($"\n\t{name} \n\t"); foreach (var seat in query.Where(s => s.SectionId == section.SectionId)) { builder.Append($"{seat.Row}{seat.Col} {seat.Status};"); } } builder.Append("\n"); return(builder.ToString()); } }
public IEnumerable <AirportViewModel> Retreive() { using (var context = new ABS()) { List <Airport> airports = new List <Airport>(); airports = context.Airports.ToList(); if (airports == null) { return(null); } { List <AirportViewModel> airportsDisplay = new List <AirportViewModel>(); foreach (var airport in airports) { var airportDisplay = new AirportViewModel() { AirportId = airport.AirportId, Name = airport.Name }; airportsDisplay.Add(airportDisplay); } return(airportsDisplay); } } }
public IEnumerable <Section> Retreive() { using (var context = new ABS()) { return(context.Sections.ToList()); } }
public List <SeatViewModel> AllSeatsForFlight(int FlightId) { using (var context = new ABS()) { var seatForFlight = context.Seats.Include(co => co.Section) .Where(s => s.FlightId == FlightId) .ToList(); List <SeatViewModel> seatsDisplay = new List <SeatViewModel>(); if (seatForFlight == null) { return(null); } foreach (var seat in seatForFlight) { var seatDisplay = new SeatViewModel() { SeatId = seat.SeatId, Col = seat.Col, Row = seat.Row, Status = seat.Status, Section = seat.Section.SeatClassName, FlightId = seat.FlightId }; seatsDisplay.Add(seatDisplay); } return(seatsDisplay); } }
public IEnumerable <FlightDisplayViewModel> Retreive() { using (var context = new ABS()) { List <Flight> flights = new List <Flight>(); flights = context.Flights.ToList(); if (flights == null) { return(null); } List <FlightDisplayViewModel> flightsDisplay = new List <FlightDisplayViewModel>(); foreach (var flight in flights) { var flightDisplay = new FlightDisplayViewModel() { FlightId = flight.FlightId, FlightName = flight.FlightName, Airline = flight.Airline.Name, OriginAirport = flight.Airport.Name, DestinationAirport = flight.Airport1.Name, Date = flight.Date }; if (flight.Seats.Count != 0) { flightDisplay.HasSeats = true; } flightsDisplay.Add(flightDisplay); } return(flightsDisplay); } }
public void AddSeatsForFlight(int flightId, int row, int col, int seatClassId) { using (var context = new ABS()) { // Checks if such section is already associated with the flight var existingSection = context.Seats.Where(s => s.FlightId == flightId && s.SectionId == seatClassId) .FirstOrDefault(); if (existingSection != null) { throw new Exception(ExceptionHelper.ExistingSection); } List <Seat> seats = new List <Seat>(); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { Seat seatToAdd = new Seat(); seatToAdd.Col = Convert.ToChar('A' + j).ToString(); //translates the integer value to alphabethical char seatToAdd.Row = i + 1; //because we want the rows to start at 1 not at 0 seatToAdd.FlightId = flightId; seatToAdd.Status = true; seatToAdd.SectionId = seatClassId; seats.Add(seatToAdd); } } context.Seats.AddRange(seats); context.SaveChanges(); } }
public IEnumerable <Flight> RetreiveAllFlightsForAirline(Airline airline) { using (var context = new ABS()) { var flights = context.Flights.Where(f => f.AirlineId == airline.AirlineId).ToList(); return(flights); } }
public List <Seat> AllAvailableSeatsList(Flight fl) { using (var context = new ABS()) { var freeSeatForFlight = context.Seats.Include(co => co.Section) .Where(s => s.FlightId == fl.FlightId && s.Status == true) .ToList(); return(freeSeatForFlight); } }
public IEnumerable <Flight> FlightsFromOriginToDestination(Airport originAirport, Airport destinationAirport) { using (var context = new ABS()) { var flightsFromOrigToDest = context.Flights.Include(co => co.Airline) .Where(f => f.OrgAirportId == originAirport.AirportId && f.DestAirportId == destinationAirport.AirportId) .ToList(); // ToList is used to not dispose dbcontext before we need it return(flightsFromOrigToDest); }; }
public Airline Retreive(int airlineId) { using (var context = new ABS()) { var airline = context.Airlines.Where(a => a.AirlineId == airlineId).FirstOrDefault(); if (airline == null) { throw new Exception(ExceptionHelper.NonExistentAirline); } return(airline); } }
public void AddNewAirport(Airport airport) { using (var context = new ABS()) { // Tries to find airport with the same name as the passed entity and adds it to the database only if it is not found var airp = context.Airports.Where(a => a.Name == airport.Name).FirstOrDefault(); if (airp != null) { throw new Exception(ExceptionHelper.AlreadyExistentAirport); } context.Airports.Add(airport); context.SaveChanges(); } }
public bool HasAvailableSeats(Flight fl) { using (var context = new ABS()) { var freeSeatForFlight = context.Seats.Where(s => s.FlightId == fl.FlightId && s.Status == true) .FirstOrDefault(); if (freeSeatForFlight == null) { return(false); } return(true); } }
public void AddNewAirline(Airline airline) { using (var context = new ABS()) { var airline1 = context.Airlines.Where(a => a.Name == airline.Name).FirstOrDefault(); if (airline1 != null) { throw new Exception(ExceptionHelper.AlreadyExistentAirline); } context.Airlines.Add(airline); context.SaveChanges(); } }
// Retreives flight by Id public Flight Retreive(int flId) { using (var context = new ABS()) { var flight1 = context.Flights.Where(f => f.FlightId == flId) .FirstOrDefault(); if (flight1 == null) { throw new Exception(ExceptionHelper.NonExistentFlight); } return(flight1); } }
// Retreives flight by airlineID and flightName public Flight Retreive(int airlineId, string flightName) { using (var context = new ABS()) { var flight1 = context.Flights.Where(f => f.AirlineId == airlineId && f.FlightName == flightName) .FirstOrDefault(); if (flight1 == null) { throw new Exception(ExceptionHelper.NonExistentFlight); } return(flight1); } }
/// <summary> /// Retreives all airlines /// </summary> /// <returns></returns> public string DisplayAirlinesDetails() { StringBuilder builder = new StringBuilder(); using (var context = new ABS()) { foreach (Airline airline in context.Airlines) { builder.Append($"{airline.Name}\n"); } } return(builder.ToString()); }
/*public bool BookSeat(Flight flight, SeatClass seatClass, int row, string col) * { * using (var context = new ABS()) * { * var section = context.Sections.Where(s => s.SeatClassName == seatClass.ToString()) * .FirstOrDefault(); * var seatToBook = context.Seats.Where(s => s.FlightId == flight.FlightId * && s.SectionId == section.SectionId * && s.Row == row * && s.Col == col) * .FirstOrDefault(); * * if (seatToBook.Status == false) * return false; * seatToBook.Status = false; * context.SaveChanges(); * * return true; * } * }*/ public bool BookSeat(int seatId) { using (var context = new ABS()) { var seat = context.Seats.Where(s => s.SeatId == seatId).FirstOrDefault(); if (seat.Status == false) { return(false); } seat.Status = false; context.SaveChanges(); return(true); } }
/// <summary> /// Рetreives and airline by airline name. /// </summary> /// <param name="airlineName"></param> /// <returns></returns> public Airline Retreive(string airlineName) { if (String.IsNullOrEmpty(airlineName)) { throw new Exception(ExceptionHelper.NullAirlineName); } using (var context = new ABS()) { var airline = context.Airlines.Where(a => a.Name == airlineName).FirstOrDefault(); if (airline == null) { throw new Exception(ExceptionHelper.NonExistentAirline); } return(airline); } }
public void AddNewFlight(Flight flight) { using (var context = new ABS()) { var flight1 = context.Flights.Where(f => f.AirlineId == flight.AirlineId && f.FlightName == flight.FlightName) .FirstOrDefault(); if (flight1 != null) { throw new Exception(ExceptionHelper.AlreadyExistentFlight); } if (flight.OrgAirportId == flight.DestAirportId) { throw new Exception(ExceptionHelper.SameOriginAndDestination); } context.Flights.Add(flight); context.SaveChanges(); } }
public string DisplayFlightsDetails() { StringBuilder builder = new StringBuilder(); using (var context = new ABS()) { foreach (Flight flight in context.Flights) { builder.Append($"\nFlight name: {flight.FlightName}, " + $"Airline: {flight.Airline.Name}, " + $"Origin: {context.Airports.Find(flight.OrgAirportId).Name}, " + $"Destination: {context.Airports.Find(flight.DestAirportId).Name}, " + $"Date: {flight.Date.ToString("dd.MM.yyyy")} \n Seats: \n"); builder.Append(SeatRepository.DisplayDetailsForSeatsInFlight(flight)); } } return(builder.ToString()); }
public SeatViewModel Retreive(int seatId) { using (var context = new ABS()) { var seat = context.Seats.Where(s => s.SeatId == seatId).FirstOrDefault(); if (seat == null) { return(null); } SeatViewModel seatDisplay = new SeatViewModel() { SeatId = seat.SeatId, Col = seat.Col, Row = seat.Row, Status = seat.Status, Section = seat.Section.SeatClassName, FlightId = seat.FlightId }; return(seatDisplay); } }
public string DisplaySeatsDetails() { StringBuilder builder = new StringBuilder(); using (var context = new ABS()) { foreach (var flight in context.Flights) { var query = context.Seats.Where(s => s.FlightId == flight.FlightId); foreach (string name in Enum.GetNames(typeof(SeatClass))) { var section = context.Sections.Where(m => m.SeatClassName == name) .FirstOrDefault(); builder.Append($"\n {name} \n"); foreach (var seat in query.Where(s => s.SectionId == section.SectionId)) { builder.Append($"{seat.Col}{seat.Row} {seat.Status};"); } } } return(builder.ToString()); } }
public IEnumerable <AirlineViewModel> Retreive() { using (var context = new ABS()) { List <Airline> airlines = new List <Airline>(); airlines = context.Airlines.ToList(); if (airlines == null) { return(null); } List <AirlineViewModel> airlinesDisplay = new List <AirlineViewModel>(); foreach (var airline in airlines) { AirlineViewModel airlineDisplay = new AirlineViewModel() { AirlineId = airline.AirlineId, Name = airline.Name }; airlinesDisplay.Add(airlineDisplay); } return(airlinesDisplay); } }