Exemplo n.º 1
0
        public void TestUpdateFlight()
        {
            Flight flightItem = flightsList.First();

            AutoMapperConfig.Initialize();
            var controller = new FlightController(_flightBLL, _airportBLL);

            flightItem.DepartureAirportId          = 5;
            flightItem.DestinationAirportId        = 10;
            flightItem.FlightTime                  = 2;
            flightItem.AirCratfFuelComsumpDistance = 400;
            flightItem.TakeOffEffort               = 50;

            var result = controller.UpdadteFlight(flightItem);

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Code, "OK");

            FlightModel model = controller.GetFlightById(flightItem.Id);

            Assert.AreEqual(flightItem.FlightTime, model.FlightTime);
            Assert.AreEqual(flightItem.TakeOffEffort, model.TakeOffEffort);
            Assert.AreEqual(flightItem.AirCratfFuelComsumpDistance, model.AirCratfFuelComsumpDistance);
            Assert.AreEqual(flightItem.DepartureAirportId, model.DepartureAirportId);
            Assert.AreEqual(flightItem.DestinationAirportId, model.DestinationAirportId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Notify the client that a flight is about to start.
        /// </summary>
        /// <param name="flight">The FlightModel instance that about to enter base station.</param>
        public void FlightAdded(FlightModel flight)
        {
            IHubContext _hub      = GlobalHost.ConnectionManager.GetHubContext <FlightsHub>();
            var         flightDto = flight.ConvertToFlightDto();

            _hub.Clients.All.FlightMove(flightDto);
        }
Exemplo n.º 3
0
        public int SoldTicketsCount(FlightModel flight)
        {
            var flightEntity = _flightMapper.MapToEntity(flight);
            var tickets      = new List <Ticket>(_uof.Tickets.GetAllWithIncludes());

            return(tickets.Count);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Check if the flights is first in the list or earlier than the first.
 /// </summary>
 /// <param name="flight">The flight being added</param>
 /// <returns></returns>
 private bool IsFirstOrEarlier(FlightModel flight)
 {
     //lock (_lockObject)
     {
         return(_flightTimeModels.First == null || First.CompareTo(flight) > 0);
     }
 }
Exemplo n.º 5
0
        public async Task <FlightModel> SaveFlight(VivaAirApiResponse flight)
        {
            try
            {
                FlightModel newFlight = new FlightModel()
                {
                    DepartureStation = flight.DepartureStation,
                    DepartureDate    = flight.DepartureDate,
                    ArrivalStation   = flight.ArrivalStation,
                    Currency         = flight.Currency,
                    Price            = flight.Price,
                    Transport        = new TransportModel()
                    {
                        FlightNumber = flight.FlightNumber
                    }
                };
                db.Flights.Add(newFlight);
                await db.SaveChangesAsync();

                return(newFlight);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts Flight entity to FlightModel
        /// </summary>
        public static Flight ToEntity(this FlightModel flightModel)
        {
            Flight flight = new Flight();

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

            flight.Id         = flightModel.Id;
            flight.Identifier = flightModel.Identifier;

            if (flightModel.DepartureAirportId > 0)
            {
                flight.DepartureAirport      = new Airport();
                flight.DestinationAirport.Id = flightModel.DepartureAirportId;
            }
            if (flightModel.DestinationAirportId > 0)
            {
                flight.DestinationAirport    = new Airport();
                flight.DestinationAirport.Id = flightModel.DestinationAirportId;
            }
            if (flightModel.AircraftId > 0)
            {
                flight.Aircraft    = new Aircraft();
                flight.Aircraft.Id = flightModel.AircraftId;
            }
            flight.Days = flightModel.Days;

            return(flight);
        }
Exemplo n.º 7
0
        public void EditFlight(FlightModel flightModel)
        {
            var entity = _flightMapper.MapToEntity(flightModel);

            _uof.Flights.Update(entity);
            _uof.Complete();
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Create(FlightViewModel model)
        {
            var airportsList = await GetAirportModelList();

            if (!ModelState.IsValid)
            {
                model.AirportsList = new List <SelectListItem>();
                foreach (var airportModel in airportsList)
                {
                    model.AirportsList.Add(new SelectListItem {
                        Text = airportModel.Name, Value = airportModel.AirportId.ToString()
                    });
                }

                return(View(model));
            }
            var flightModel = new FlightModel
            {
                Name               = model.Name,
                DepartureAirport   = airportsList.FirstOrDefault(airport => airport.AirportId.Equals(model.DepartureAirportId)),
                DestinationAirport = airportsList.FirstOrDefault(airport => airport.AirportId.Equals(model.DestinationAirportId))
            };

            ExecutePostAction(JsonConvert.SerializeObject(flightModel), Constants.CreateFlightActionName);
            return(RedirectToAction("Index", "Flight/Index"));
        }
 public static void Update(this FlightModel dbFlight, UpsertFlightModel flight)
 {
     dbFlight.From  = flight.From;
     dbFlight.To    = flight.To;
     dbFlight.Price = flight.Price;
     dbFlight.Date  = flight.Date;
 }
Exemplo n.º 10
0
        public async Task TestCreateAircraft()
        {
            // Arrange
            string   testId   = "1100";
            Flight   flight   = GetTestFlights().FirstOrDefault(p => p.Id == testId);
            Aircraft aircraft = GetTestAircrafts().FirstOrDefault(p => p.Id == testId);

            FlightModel   flightmodel   = GetTestFlightsModels().FirstOrDefault(p => p.Id == testId);
            AircraftModel aircraftmodel = GetTestAircraftsModels().FirstOrDefault(p => p.Id == testId);

            var mockRepoAircraft = new Mock <IAircraftRepository>();
            var mockRepoFlight   = new Mock <IFlightRepository>();

            mockRepoFlight.Setup(c => c.Add(flight));
            mockRepoAircraft.Setup(c => c.Add(aircraft));
            var controller = new AircraftController(mockRepoAircraft.Object);

            // Act
            var result = controller.Post(aircraftmodel);

            // Assert
            var actionResult = Assert.IsType <OkResult>(result);

            var model = Assert.IsType <OkResult>(actionResult);
        }
Exemplo n.º 11
0
        public ActionResult Index(FlightTime fp)
        {
            FlightDal     fd = new FlightDal();
            FlightDetails f  = new FlightDetails();

            f.Arrival_Airport = fp.ArrivalAirport;
            f.Depart_Airport  = fp.DepartureAirport;
            f.Depart_Time     = fp.FlightDate;
            List <FlightDetails> mylist = new List <FlightDetails>();
            List <FlightModel>   flist  = new List <FlightModel>();

            mylist = fd.FindFlights(f);

            foreach (var item in mylist)
            {
                FlightModel fm = new FlightModel();
                fm.Amount           = item.Amount;
                fm.Arrival_Airport  = item.Arrival_Airport;
                fm.Depart_Airport   = item.Depart_Airport;
                fm.Arrival_Time     = item.Arrival_Time;
                fm.Depart_Time      = item.Depart_Time;
                fm.Flightno         = item.Flightno;
                fm.Seating_Capacity = item.Seating_Capacity;
                fm.Availaible_Seat  = fd.FindSeat(item.Flightno);
                flist.Add(fm);
            }

            TempData["FP"] = flist;
            return(RedirectToAction("ShowFlights"));
        }
        public ActionResult Display(string ip, int port, int?time = 0)
        {
            FlightModel flightModel = FlightModel.Instance;

            FlightModel.Instance.InitializeList();
            FlightModel.Instance.SetCountDisplays();
            ViewBag.countDisplays = FlightModel.Instance.GetCountDisplays();

            System.Net.IPAddress validIp = null;
            ViewBag.readFromFile = 0;
            // Check if the given parameter is valid ip address
            if (System.Net.IPAddress.TryParse(ip, out validIp))
            {
                // Connect to the simulator server with the appropriate ip and port
                flightModel.InitialClient(ip, port);
                ViewBag.time = time;
            }
            else
            {
                // update the variables according to the third option
                ViewBag.readFromFile = 1;
                ViewBag.time         = port;
                ViewBag.fileName     = ip;
            }
            return(View());
        }
Exemplo n.º 13
0
        public int Update(FlightModel flight)
        {
            this.FlightRepository.Update(flight.GetModel());
            var result = this.UnitOfWork.SaveChanges();

            return(result);
        }
Exemplo n.º 14
0
        //PUT : FLIGHT
        public async Task <Message <FlightModel> > PutFlight(int id, FlightModel fm)
        {
            var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                            "Flight/" + id));

            return(await PutAsync <FlightModel>(requestUrl, fm));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Adds a flight to the database and the time manager queue.
        /// </summary>
        /// <param name="flight">The FlightModel instance to add the database and the time manager queue.</param>
        /// <returns>The FlightModel entity instance after being processed by the Repository</returns>
        public FlightModel AddFlight(FlightModel flight)
        {
            flight = _flightsRepository.Add(flight);
            _flightsTimeManager.Add(flight);

            return(flight);
        }
Exemplo n.º 16
0
        public FlightViewModel(FlightModel flight)
        {
            if (flight != null)
            {
                this.Id          = flight.Id;
                this.Title       = flight.Title;
                this.Price       = flight.Price;
                this.Duration    = flight.Duration;
                this.TravelClass = flight.TravelClass;
                if (flight.Airline != null)
                {
                    this.Airline = flight.Airline.Name;
                }

                if (flight.DepartureAirport != null)
                {
                    this.DepartureAirport = flight.DepartureAirport.Name;
                }

                if (flight.ArrivalAirport != null)
                {
                    this.ArrivalAirport = flight.ArrivalAirport.Name;
                }
            }
        }
        private bool EditFlight(FlightModel flight)
        {
            var editWindow = new EditFlightWindow();
            var ctx        = (EditFlightViewModel)editWindow.DataContext;
            var flightCopy = new FlightModel();

            CopyFields(flight, flightCopy);
            ctx.Flight            = flightCopy;
            ctx.Routes            = _routeService.GetAllRoutes();
            ctx.Airplanes         = _airplaneService.GetAllAirplanes();
            flightCopy.RouteModel = ctx.Routes.Single(r => r.Id == flightCopy.RouteModel.Id);
            if (editWindow.ShowDialog() != true)
            {
                return(false);
            }

            var errs = GetModelErrors(flightCopy);

            if (errs != string.Empty)
            {
                ShowError(errs, "Error! Saving cancelled. ");
                return(false);
            }

            CopyFields(flightCopy, flight);
            _flightService.EditFlight(flight);
            return(true);
        }
Exemplo n.º 18
0
        public List <FlightModel> search(String query)
        {
            List <FlightModel> flights = new List <FlightModel>();

            Connection.Open();
            Command.Connection  = Connection;
            Command.CommandText = query;
            using (SqlDataReader reader = Command.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        FlightModel Flight = new FlightModel();
                        Flight.Flight_ID         = reader.GetInt32(0);
                        Flight.Plane.AirCraft_ID = reader.GetInt32(1);
                        Flight.Departure_Place   = reader.GetString(2);
                        Flight.Landing_Place     = reader.GetString(3);
                        Flight.Departure_Date    = reader.GetDateTime(4);
                        Flight.Landing_Date      = reader.GetDateTime(5);
                        Flight.Flight_Type       = reader.GetString(6);
                        flights.Add(Flight);
                    }
                    return(flights);
                }
                else
                {
                    Message = "Not found";
                }
            }
            Connection.Close();
            return(null);
        }
Exemplo n.º 19
0
        public void AddFlight(FlightModel flight)
        {
            var entity = _flightMapper.MapToEntity(flight);

            _uof.Flights.Add(entity);
            _uof.Complete();
        }
Exemplo n.º 20
0
        public void ReturnViewWithModelWithCorrectProperties_WhenThereIsAModelWithThePassedId()
        {
            // Arrange
            var flightServiceMock  = new Mock <IFlightService>();
            var airlineServiceMock = new Mock <IAirlineService>();
            var flightModel        = new FlightModel()
            {
                Id          = Guid.NewGuid(),
                Title       = "BA123",
                Price       = 50,
                Duration    = TimeSpan.Parse("01:10:00"),
                TravelClass = TravelClass.First
            };

            var flightViewModel = new FlightViewModel(flightModel);

            flightServiceMock.Setup(m => m.GetById(flightModel.Id)).Returns(flightModel);

            var flightController = new FlightController(flightServiceMock.Object, airlineServiceMock.Object);

            // Act & Assert
            flightController
            .WithCallTo(b => b.Details(flightModel.Id))
            .ShouldRenderDefaultView()
            .WithModel <FlightViewModel>(viewModel =>
            {
                Assert.AreEqual(flightModel.Title, viewModel.Title);
                Assert.AreEqual(flightModel.Price, viewModel.Price);
                Assert.AreEqual(flightModel.Duration, viewModel.Duration);
                Assert.AreEqual(flightModel.TravelClass, viewModel.TravelClass);
            });
        }
Exemplo n.º 21
0
        public void ReturnFlights_WhitPriceLessThanTheInput()
        {
            // Arrange
            var flightServiceMock  = new Mock <IFlightService>();
            var airlineServiceMock = new Mock <IAirlineService>();

            var collectionFlightModels = new List <FlightModel>();

            for (int i = 0; i < 2; i++)
            {
                var flightModel = new FlightModel()
                {
                    Id          = Guid.NewGuid(),
                    Title       = "BA123" + i,
                    Price       = 50 + i,
                    Duration    = TimeSpan.Parse("01:10:00") + TimeSpan.FromHours(i),
                    TravelClass = TravelClass.First
                };
                collectionFlightModels.Add(flightModel);
            }

            var collectionFlighViewtModels = new List <FlightViewModel>();

            flightServiceMock.Setup(x => x.GetFlightByPrice(100)).Returns(collectionFlightModels);

            var flightController = new FlightController(flightServiceMock.Object, airlineServiceMock.Object);

            // Act
            var result = flightController.FilteredFlights(100);

            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 22
0
        public async Task <ActionResult <FlightModel> > GetFlight(int id)
        {
            Flight flight = context.Flights.Include(x => x.Seats).Include(x => x.FlightDestinations).ThenInclude(x => x.Destination).SingleOrDefault(x => x.Id == id);

            FlightModel fTemp = new FlightModel();

            if (flight == null)
            {
                return(NoContent());
            }
            else
            {
                fTemp.Id          = flight.Id;
                fTemp.Departure   = flight.Departure;
                fTemp.Arrival     = flight.Arrival;
                fTemp.Connections = new List <string>();
                foreach (var item in flight.FlightDestinations)
                {
                    fTemp.Connections.Add(item.Destination.City);
                }
                fTemp.TouchDown      = flight.TouchDown;
                fTemp.TakeOff        = flight.TakeOff;
                fTemp.Length         = flight.Length;
                fTemp.NumberBusiness = flight.Seats.Where(x => x.Class == Class.BUSINESS).Count();
                fTemp.NumberEconomy  = flight.Seats.Where(x => x.Class == Class.ECONOMY).Count();
                fTemp.NumberFirst    = flight.Seats.Where(x => x.Class == Class.FIRST).Count();
                fTemp.PriceBusiness  = flight.Seats.FirstOrDefault(x => x.Class == Class.BUSINESS).Price;
                fTemp.PriceEconomy   = flight.Seats.FirstOrDefault(x => x.Class == Class.ECONOMY).Price;
                fTemp.PriceFirst     = flight.Seats.FirstOrDefault(x => x.Class == Class.FIRST).Price;
            }
            return(fTemp);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Adds a flight to the time pueue.
 /// </summary>
 /// <param name="flight">The FlightModel instance to add the the time manager queue.</param>
 public void Add(FlightModel flight)
 {
     lock (_lockObject)
     {
         if (IsFirstOrEarlier(flight))
         {
             if (_timer != null)
             {
                 KillTimer();
             }
             _flightTimeModels.AddFirst(flight);
             SetTimer();
             _timer.Start();
         }
         else
         {
             var tmp = _flightTimeModels.First;
             while (NextNodeIsntNullOrEarlier(flight, tmp))
             {
                 tmp = tmp.Next;
             }
             _flightTimeModels.AddAfter(tmp, flight);
         }
     }
 }
Exemplo n.º 24
0
        public FlightModel CreateFlight(int departureAirportId, int arrivalAirportId)
        {
            var flight = new FlightModel();

            var arrivalAirport   = _airportBusiness.GetAirportById(arrivalAirportId);
            var departureAirport = _airportBusiness.GetAirportById(departureAirportId);

            flight.ArrivalAirport   = arrivalAirport ?? new AirportModel();
            flight.DepartureAirport = departureAirport ?? new AirportModel();

            if (arrivalAirport != null && departureAirport != null)
            {
                flight.Distance  = _flightService.CalculateDistanceWithHaversineFormulae(arrivalAirport.Coordinates, departureAirport.Coordinates);
                flight.Duration  = _flightService.CalculateTimeOfFlight(flight.Distance, _speed);
                flight.Carburant = _flightService.CalculateFuelVolumeForFlight(flight.Distance, _fuelConsumption, departureAirport.TakeOffEffort);
            }

            flight.Creation = DateTime.Today;

            var flightEntity = SetFlightEntity(flight);

            _TUIAssessmentDAL.SaveFlightEntity(flightEntity);

            return(flight);
        }
Exemplo n.º 25
0
        public static async Task <string> addFlightToDatabase(WebhookRequest request, FlightsAPIContext _apiContext, FlightContext _dbContext)
        {
            // Extracts the parameters of the request
            var    requestParameters = request.QueryResult.Parameters;
            string fromCity          = requestParameters.Fields["from-city"].StringValue;
            string toCity            = requestParameters.Fields["to-city"].StringValue;

            DateTime departure = DateTimeOffset.Parse(requestParameters.Fields["date-time"].StringValue).UtcDateTime.Date;
            var      flight    = await _apiContext.GetFlight(fromCity, toCity, departure);

            if (flight.Quotes.Any())
            {
                FlightModel flightItem = new FlightModel
                {
                    FromCity      = flight.Places.Where(p => p.PlaceId == flight.Quotes[0].OutboundLeg.OriginId).First().Name,
                    ToCity        = flight.Places.Where(p => p.PlaceId == flight.Quotes[0].OutboundLeg.DestinationId).First().Name,
                    DepartureDate = flight.Quotes[0].OutboundLeg.DepartureDate.Date,
                    Price         = flight.Quotes[0].MinPrice,
                };
                _dbContext.Add(flightItem);
                await _dbContext.SaveChangesAsync();

                textToReturn = "Done!";
            }
            else
            {
                textToReturn = "Could not add a flight";
            }
            return(textToReturn);
        }
Exemplo n.º 26
0
        public IActionResult Edit(int id)
        {
            var         model       = new FlightViewModel();
            FlightModel flightModel = model.Load(id);

            return(View(flightModel));
        }
 public void AcceptFlight(FlightModel flight)
 {
     if (matchElement(this.fromAirport, flight.From) && matchElement(this.toAirport, flight.To))
     {
         flights.Add(flight);
     }
 }
Exemplo n.º 28
0
        public IActionResult Edit(FlightModel model)
        {
            var flightUpModel = new FlightUpdateModel();

            flightUpModel.UpdateFlight(model);
            return(RedirectToAction(nameof(FlightController.Index)));
        }
        public bool AddFlight(FlightModel flight)
        {
            List <FlightModel> flightData = FlightDataInitialization.FlightData(flight.GateID);

            flightData.Add(flight);
            return(true);
        }
Exemplo n.º 30
0
        public ActionResult DeleteFlight(int Id)
        {
            Flight      flight      = FlightBL.GetFlightDetails(Id);
            FlightModel flightModel = AutoMapper.Mapper.Map <Flight, FlightModel>(flight); //Auto Mapper entity to model

            return(View(flightModel));                                                     //Calling View for the Delste Flight
        }