public void Flight_AddNew()
        {
            FlightRepository repository = new FlightRepository(dbConnectionString);
            var flightList = repository.GetAll();
            var prevCount  = flightList.ToList().Count;

            var rndNo = new Random().Next(10, 999);

            Flight flight = new Flight
            {
                Number            = "FL" + rndNo.ToString(),
                Name              = "Test Flight Name",
                DepartureCity     = "Craigieburn",
                DepartureTime     = DateTime.Now,
                ArrivalCity       = "Melbourne",
                ArrivalTime       = DateTime.Now.AddHours(4),
                PassengerCapacity = 20
            };

            var result = repository.Add(flight);

            flightList = repository.GetAll();
            var afterCount = flightList.ToList().Count;

            Assert.AreEqual(1, result);
            Assert.IsTrue(prevCount > 0);
            Assert.IsTrue(afterCount > 0);
            Assert.IsTrue(afterCount > prevCount);
        }
        public IActionResult GetAll()
        {
            IEnumerable <Flight> flightList;

            try
            {
                flightList = flightRepository.GetAll();

                if (flightList == null)
                {
                    return(NoContent());
                }

                if (flightList.ToList().Count == 0)
                {
                    return(NoContent());
                }
            }
            catch
            {
                return(BadRequest());
            }

            return(Ok(flightList));
        }
示例#3
0
        private void RefreshcbBuses()
        {
            CitiRepository cityRep = new CitiRepository();

            RefreshBindingSourse();
            dtpDepartureDate.MinDate   = DateTime.Now;
            dtpArrivalDate.MinDate     = DateTime.Now;
            dtpFinalDateFlight.MinDate = DateTime.Now;

            cbCityStart.DisplayMember = "CityName";
            cbCityStart.ValueMember   = "CityId";
            cbCityStart.DataSource    = cityRep.GetAll();

            cbCityEnd.DisplayMember = "CityName";
            cbCityEnd.ValueMember   = "CityId";
            cbCityEnd.DataSource    = cityRep.GetAll();

            BusRepository    busRep    = new BusRepository();
            FlightRepository flightRep = new FlightRepository();
            var busybus   = flightRep.GetAll().Select(p => p.BusId).ToList();
            int count     = 0;
            var tempBuses = busRep.GetAll();

            while (count < busybus.Count)
            {
                tempBuses = tempBuses.Where(p => p.BusId != busybus[count]).ToList();
                count++;
            }
            cbBuses.DisplayMember = "BusName";
            cbBuses.ValueMember   = "BusId";
            cbBuses.DataSource    = tempBuses;
        }
示例#4
0
        public void UpdateUsingTwoRepositories()
        {
            LocationRepository locationRepository = new LocationRepository();
            FlightRepository   flightRepository = new FlightRepository();
            Flight             flight, flightFromDb;
            Location           location;

            using (TransactionScope scope = new TransactionScope())
            {
                // Update flight and location
                flight = flightRepository.FindBy(f => f.FlightNumber == "BY001").Single();
                flight.FlightNumber = "BY001_updated";
                // Since the flight was retrieved using the current repository,
                // we don't need to call the Edit method
                flightRepository.Save();

                location      = locationRepository.FindBy(l => l.City == "Rome").Single();
                location.City = "Rome_updated";
                // Since the location was retrieved using the current repository,
                // we don't need to call the Edit method
                locationRepository.Save();

                //TODO: Lab 02, Exercise 2 Task 5.2 : Review the query for the updated flight that is inside the transaction scope
                flightFromDb = (from f in flightRepository.GetAll()
                                where f.Source.City == "Rome_updated"
                                select f).FirstOrDefault();

                Assert.IsNotNull(flightFromDb);
                Assert.AreEqual(flightFromDb.FlightNumber, "BY001_updated");

                // Do not commit the transaction
                //scope.Complete();
            }


            //TODO: Lab 02, Exercise 2 Task 5.4 : Review the query for the updated flight that is outside the transaction scope
            flightFromDb = (from f in flightRepository.GetAll()
                            where f.Source.City == "Rome_updated"
                            select f).FirstOrDefault();

            Assert.IsNull(flightFromDb);

            locationRepository.Dispose();
            flightRepository.Dispose();
        }
        public void Flight_GetAll()
        {
            FlightRepository repository = new FlightRepository(dbConnectionString);
            var flightList = repository.GetAll();
            var count      = flightList.ToList().Count;

            Assert.IsNotNull(flightList);
            Assert.IsTrue(count > 0);
        }
        public Task <Flight> Handle(GetFlightByNumberRequest request, CancellationToken cancellationToken)
        {
            var flight = _flightRepository.GetAll()
                         .SingleOrDefault(f => f.Number.Equals(request.Number, StringComparison.OrdinalIgnoreCase));

            if (flight == null)
            {
                throw new DomainObjectNotFoundException($"Flight with number '{request.Number}' not found");
            }

            return(Task.FromResult(flight));
        }
示例#7
0
        public void GetSingleFlight()
        {
            using (var repository = new FlightRepository())
            {
                var query = from f in repository.GetAll()
                            where f.FlightNumber == "BY001"
                            select f;

                var flight = query.FirstOrDefault();

                Assert.IsNotNull(flight);
            }
        }
示例#8
0
        public Booking BookFlight(BookingFlightModel model)
        {
            var flight = _flightRepository.GetAll()
                         .SingleOrDefault(f => f.Number == model.FlightNumber);

            if (flight == null)
            {
                return(null);
            }

            var customer = new Person
            {
                Id        = new Random().Next(0, 10000),
                Name      = model.Customer.Name,
                Address   = model.Customer.Address,
                Email     = model.Customer.Email,
                DateBirth = model.Customer.DateBirth,
                Gender    = model.Customer.Gender
            };

            var passengers = model.Passengers.Select(passenger => new Person
            {
                Id        = new Random().Next(0, 10000),
                Name      = passenger.Name,
                Address   = passenger.Address,
                Email     = passenger.Email,
                DateBirth = passenger.DateBirth,
                Gender    = passenger.Gender
            })
                             .ToList();

            var booking = new Booking
            {
                Id          = new Random().Next(0, 10000),
                Number      = model.BookNumber,
                Flight      = flight,
                Customer    = customer,
                Passengers  = passengers,
                DateBooking = DateTime.Parse(
                    DateTime.Now.ToLongTimeString(),
                    new CultureInfo("nl-NL"))
            };

            _bookingRepository.Save(booking);

            return(booking);
        }
示例#9
0
        public void GetFlightWithLocationsLazyLoad()
        {
            Flight flight;

            using (var repository = new FlightRepository())
            {
                var query = from f in repository.GetAll()
                            where f.FlightNumber == "BY001"
                            select f;

                flight = query.FirstOrDefault();

                Assert.IsNotNull(flight);
                Assert.IsNotNull(flight.Source);
                Assert.IsNotNull(flight.Destination);
            }
        }
示例#10
0
        public void GetFlightWithLocationsFailedLazyLoad()
        {
            Flight flight;

            using (var repository = new FlightRepository())
            {
                var query = from f in repository.GetAll()
                            where f.FlightNumber == "BY001"
                            select f;

                flight = query.FirstOrDefault();
            }

            Assert.IsNotNull(flight);

            // We haven't eager loaded the flight source,
            // and the context is disposed, so lazy load will fail
            Assert.IsNotNull(flight.Source);
        }
示例#11
0
        public IActionResult Add(FlightViewModel model, string returnUrtl = null)
        {
            var flight = new FlightModel {
                Id                   = model.Id,
                AirplaneId           = model.AirplaneId,
                AviaCompanyId        = model.AviaCompanyId,
                HomeAirportId        = model.HomeAirportId,
                DestinationAirportId = model.DestinationAirportId,
                Departure            = model.Departure,
                Arrival              = model.Arrival
            };
            var curFlights = _flights.GetAll().ToList().OrderByDescending(item => item.Id);

            if (curFlights.Count() == 0)
            {
                flight.Id = 1;
            }
            else
            {
                flight.Id = curFlights.First().Id + 1;
            }
            _flights.Add(flight);
            return(RedirectToAction("Index"));
        }
示例#12
0
        private void EditBus()
        {
            listSeats.Clear();
            Buses                  bus           = binSourceBusStation.Current as Buses;
            BusRepository          busrep        = new BusRepository();
            List <TempFlightId>    listFlightId2 = new List <TempFlightId>();
            List <TempSeatId>      listSeatId    = new List <TempSeatId>();
            List <BusinessTickets> busTicketsB   = DeleteTicketsFlightsSeats(bus, ref listbusFlights, ref listSeats);

            busrep.Delete(bus);

            Buses newbus = new Buses();

            newbus.BusName     = bus.BusName;
            newbus.CountSeats  = bus.CountSeats;
            newbus.Information = bus.Information;
            busrep.Create(newbus);

            if (listbusFlights.Count > 0)
            {
                BusinessFlights           busFlight;
                BusinessFlightsRepository busFlightrep = new BusinessFlightsRepository();
                TempFlightId ekz;
                for (int i = 0; i < listbusFlights.Count; i++)
                {
                    busFlight = new BusinessFlights();
                    ekz       = new TempFlightId();
                    busFlight.FlightNumber  = listbusFlights[i].FlightNumber;
                    busFlight.CityIdStart   = listbusFlights[i].CityIdStart;
                    busFlight.CityIdEnd     = listbusFlights[i].CityIdEnd;
                    busFlight.DepartureDate = listbusFlights[i].DepartureDate;
                    busFlight.DepartureTime = listbusFlights[i].DepartureTime;
                    busFlight.ArrivalDate   = listbusFlights[i].ArrivalDate;
                    busFlight.ArrivaTime    = listbusFlights[i].ArrivaTime;
                    busFlight.BusId         = listbusFlights[i].BusId == bus.BusId ? newbus.BusId : listbusFlights[i].BusId;
                    busFlight.Price         = listbusFlights[i].Price;
                    busFlightrep.Create(busFlight);

                    FlightRepository newflight = new FlightRepository();
                    ekz.oldId = listbusFlights[i].FlightId;
                    ekz.newId = newflight.GetAll().Select(p => p.FlightId).Last();
                    listFlightId2.Add(ekz);
                }
            }


            SeatsRepository seatrep = new SeatsRepository();
            TempSeatId      ekzseat;

            for (int i = 0; i < newbus.CountSeats; i++)
            {
                Seats seat = new Seats();
                ekzseat         = new TempSeatId();
                seat.BusId      = newbus.BusId;
                seat.NumberSeat = i + 1;
                seatrep.Create(seat);

                SeatsRepository newSeat = new SeatsRepository();
                ekzseat.oldId = i < listSeats.Count ? listSeats[i].SeatId : 0;
                ekzseat.newId = newSeat.GetAll().Select(p => p.SeatId).Last();
                listSeatId.Add(ekzseat);
            }

            if (busTicketsB.Count > 0)
            {
                BusinessTickets           bustick;
                BusinessTicketsRepository bustickrep = new BusinessTicketsRepository();
                for (int i = 0; i < busTicketsB.Count; i++)
                {
                    bustick = new BusinessTickets();
                    for (int j = 0; j < listFlightId2.Count; j++)
                    {
                        if (busTicketsB[i].FlightId == listFlightId2[j].oldId)
                        {
                            bustick.FlightId = listFlightId2[j].newId;
                            break;
                        }
                    }
                    for (int k = 0; k < listSeatId.Count; k++)
                    {
                        if (busTicketsB[i].SeatId == listSeatId[k].oldId)
                        {
                            bustick.SeatId = listSeatId[k].newId;
                            break;
                        }
                    }
                    bustick.ReleaseDate = busTicketsB[i].ReleaseDate;
                    bustick.DiscountId  = busTicketsB[i].DiscountId;
                    bustick.Sold        = busTicketsB[i].Sold;
                    bustick.Reserve     = busTicketsB[i].Reserve;
                    bustick.Canceled    = busTicketsB[i].Canceled;

                    bustickrep.Create(bustick);
                }
            }

            MessageBox.Show("Bus Edit");
        }
示例#13
0
        private void EditCity()
        {
            listbusFlights.Clear();
            Cities                 city         = binSourceBusStation.Current as Cities;
            CitiRepository         cityrep      = new CitiRepository();
            List <TempFlightId>    listFlightId = new List <TempFlightId>();
            List <BusinessTickets> busTicketsC  = DeleteTicketsANDFlights(city, ref listbusFlights);

            cityrep.Delete(city);

            Cities newcity = new Cities();

            newcity.CityName    = city.CityName;
            newcity.Information = city.Information;
            cityrep.Create(newcity);

            if (listbusFlights.Count > 0)
            {
                BusinessFlights           busFlight;
                BusinessFlightsRepository busFlightrep = new BusinessFlightsRepository();
                TempFlightId ekz;
                for (int i = 0; i < listbusFlights.Count; i++)
                {
                    busFlight = new BusinessFlights();
                    ekz       = new TempFlightId();
                    busFlight.FlightNumber  = listbusFlights[i].FlightNumber;
                    busFlight.CityIdStart   = listbusFlights[i].CityIdStart == city.CityId ? newcity.CityId : listbusFlights[i].CityIdStart;
                    busFlight.CityIdEnd     = listbusFlights[i].CityIdEnd == city.CityId ? newcity.CityId : listbusFlights[i].CityIdEnd;
                    busFlight.DepartureDate = listbusFlights[i].DepartureDate;
                    busFlight.DepartureTime = listbusFlights[i].DepartureTime;
                    busFlight.ArrivalDate   = listbusFlights[i].ArrivalDate;
                    busFlight.ArrivaTime    = listbusFlights[i].ArrivaTime;
                    busFlight.BusId         = listbusFlights[i].BusId;
                    busFlight.Price         = listbusFlights[i].Price;
                    busFlightrep.Create(busFlight);

                    FlightRepository newflight = new FlightRepository();
                    ekz.oldId = listbusFlights[i].FlightId;
                    ekz.newId = newflight.GetAll().Select(p => p.FlightId).Last();
                    listFlightId.Add(ekz);
                }
            }
            if (busTicketsC.Count > 0)
            {
                BusinessTickets           bustick;
                BusinessTicketsRepository bustickrep = new BusinessTicketsRepository();
                for (int i = 0; i < busTicketsC.Count; i++)
                {
                    bustick = new BusinessTickets();
                    for (int j = 0; j < listFlightId.Count; j++)
                    {
                        if (busTicketsC[i].FlightId == listFlightId[j].oldId)
                        {
                            bustick.FlightId = listFlightId[j].newId;
                            break;
                        }
                    }
                    bustick.ReleaseDate = busTicketsC[i].ReleaseDate;
                    bustick.SeatId      = busTicketsC[i].SeatId;
                    bustick.DiscountId  = busTicketsC[i].DiscountId;
                    bustick.Sold        = busTicketsC[i].Sold;
                    bustick.Reserve     = busTicketsC[i].Reserve;
                    bustick.Canceled    = busTicketsC[i].Canceled;

                    bustickrep.Create(bustick);
                }
            }

            MessageBox.Show("City Edit");
        }
示例#14
0
 /// <summary>
 /// Will retrieve all flights
 /// </summary>
 /// <returns></returns>
 public static IEnumerable <Flight> GetAllFlights()
 {
     return(_flightRepository.GetAll());
 }
示例#15
0
        internal static void Main()
        {
            // Test connection to SQL Server
            Database.SetInitializer(new MigrateDatabaseToLatestVersion <AirportSystemMsSqlDbContext, ConfigurationMSSql>());
            using (AirportSystemMsSqlDbContext db = new AirportSystemMsSqlDbContext())
            {
                db.Database.CreateIfNotExists();

                foreach (var e in db.FlightTypes)
                {
                    Console.WriteLine(e.Name);
                }
            }

            // Test Deserializers
            var xmlSer   = new XmlDeserializer();
            var jsonSer  = new JsonDeserializer();
            var excelSer = new ExcelDeserializer();

            var xmlPath   = "../../../SampleInputFiles/sample.xml";
            var jsonPath  = "../../../SampleInputFiles/sample.json";
            var excelPath = "../../../SampleInputFiles/sample.xlsx";


            // Test repository

            var msSqlData  = new AirportSystemMsSqlData(new AirportSystemMsSqlDbContext());
            var pSqlData   = new AirportSystemPSqlData(new AirportSystemPSqlDbContext());
            var sqliteData = new AirportSystemSqliteData(new AirportSystemSqliteDbContext());

            msSqlData.Airports.Add(new Airport
            {
                Code = "LBWN",
                Name = "Varna Airport"
            });

            msSqlData.Airports.Add(new Airport
            {
                Code = "LBSF",
                Name = "Sofia Airport"
            });

            msSqlData.Airlines.Add(new Airline
            {
                Name = "Bongo Air"
            });

            Console.WriteLine();
            Console.WriteLine("Airports:");
            Console.WriteLine("==========");

            foreach (var entity in msSqlData.Airports.GetAll(null))
            {
                Console.WriteLine("{0} - {1}", entity.Code, entity.Name);
            }

            Console.WriteLine("Airlines:");
            Console.WriteLine("==========");
            foreach (var entity in msSqlData.Airlines.GetAll(null))
            {
                Console.WriteLine("{0}", entity.Name);
            }

            // Test shedule updater
            var su         = new ScheduleUpdater(msSqlData, pSqlData, sqliteData);
            int countAdded = 0;

            countAdded = su.UpdateScheduleFromFile(xmlPath, xmlSer);
            Console.WriteLine("{0} FLIGHTS ADDDED!!!", countAdded);
            countAdded = su.UpdateScheduleFromFile(jsonPath, jsonSer);
            Console.WriteLine("{0} FLIGHTS ADDDED!!!", countAdded);
            countAdded = su.UpdateScheduleFromFile(excelPath, excelSer);
            Console.WriteLine("{0} FLIGHTS ADDDED!!!", countAdded);
            Console.WriteLine();

            var f          = new FlightRepository(new AirportSystemMsSqlDbContext());
            var allFlights = f.GetAll(null);

            foreach (var item in allFlights)
            {
                var fl = (Flight)item;
                Console.WriteLine("{0} - {1} - {2} - {3} - {4} - {5} - {6} - {7} - {8} - {9} - {10} - {11}",
                                  fl.DestinationAirport.Name,
                                  fl.DestinationAirport.Code,
                                  fl.FlightType.Name,
                                  fl.Plane.Manufacturers.Name,
                                  fl.Terminal.Name,
                                  fl.Plane.Airlines.Name,
                                  fl.Plane.PlanePassport.RegistrationNumber,
                                  fl.Plane.PlanePassport.YearOfRegistration,
                                  fl.Plane.PlanePassport.State,
                                  fl.SheduledTime,
                                  fl.Plane.Models.Name,
                                  fl.Plane.Models.Seats);
            }

            var filteredFlights = f.GetAll(x => x.DestinationAirportId == 3);

            Console.WriteLine(filteredFlights.Count());
        }
示例#16
0
 internal IEnumerable <Flight> Get()
 {
     return(_repo.GetAll());
 }