Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
 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);
         }
     }
 }
Esempio n. 3
0
 public IEnumerable <Section> Retreive()
 {
     using (var context = new ABS())
     {
         return(context.Sections.ToList());
     }
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        public IEnumerable <Flight> RetreiveAllFlightsForAirline(Airline airline)
        {
            using (var context = new ABS())
            {
                var flights = context.Flights.Where(f => f.AirlineId == airline.AirlineId).ToList();

                return(flights);
            }
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
 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);
     };
 }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
 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();
     }
 }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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();
            }
        }
Esempio n. 14
0
        // 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);
            }
        }
Esempio n. 15
0
        // 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);
            }
        }
Esempio n. 16
0
        /// <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());
        }
Esempio n. 17
0
        /*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);
            }
        }
Esempio n. 18
0
        /// <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);
            }
        }
Esempio n. 19
0
 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();
     }
 }
Esempio n. 20
0
        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());
        }
Esempio n. 21
0
 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);
     }
 }
Esempio n. 22
0
        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());
            }
        }
Esempio n. 23
0
        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);
            }
        }