Exemplo n.º 1
0
        // GET: FlightData
        public ActionResult Index()
        {
            var model     = new FlightDataModel();
            var viewModel = model.GetViewModel();

            return(View("Index", viewModel));
        }
Exemplo n.º 2
0
        private FlightDto CollectRawData(FlightDataModel flightDataModel)
        {
            var flight = new FlightDto()
            {
                Number = flightDataModel.Number,
                From   = new CityDto()
                {
                    Id = flightDataModel.FromCity
                },
                To = new CityDto()
                {
                    Id = flightDataModel.ToCity
                },
                DepartureDate = flightDataModel.DepartureDate,
                ArrivalDate   = flightDataModel.ArrivalDate,
                Status        = _flightService.Status(flightDataModel.Status)
            };

            if (flightDataModel.Id != null)
            {
                flight.Id = flightDataModel.Id.Value;
            }

            var members = GetMemberCollection(flightDataModel);

            flight.AircrewMembers = members;

            return(flight);
        }
Exemplo n.º 3
0
        private IEnumerable <AircrewMemberDto> GetMemberCollection(FlightDataModel flightDataModel)
        {
            var members = new List <AircrewMemberDto>();

            members.AddRange(flightDataModel.Pilots.Select(x => new AircrewMemberDto()
            {
                Id = x
            }));
            members.AddRange(flightDataModel.AircraftNavigators.Select(x => new AircrewMemberDto()
            {
                Id = x
            }));
            members.AddRange(flightDataModel.RadioOperators.Select(x => new AircrewMemberDto()
            {
                Id = x
            }));
            members.AddRange(flightDataModel.FlightEngineers.Select(x => new AircrewMemberDto()
            {
                Id = x
            }));
            members.AddRange(flightDataModel.Stewardesses.Select(x => new AircrewMemberDto()
            {
                Id = x
            }));

            return(members);
        }
Exemplo n.º 4
0
        public ActionResult UpdateFlight(Guid?flightId)
        {
            var flight = _flightService.FindById(flightId.Value).Result;

            var flightModel = new FlightDataModel()
            {
                Id            = flight.Id,
                Number        = flight.Number,
                FromCity      = flight.From.Id,
                ToCity        = flight.To.Id,
                DepartureDate = flight.DepartureDate,
                ArrivalDate   = flight.ArrivalDate,
                Status        = flight.Status.GetDescription()
            };

            var cities = _cityService.GetAll().Result;

            var model = new FlightCreateUpdateModel()
            {
                FlightDataModel        = flightModel,
                Cities                 = cities,
                Statuses               = _flightService.GetAvailableStatuses().Result,
                CurrentAircrewMemebers = flight.AircrewMembers
            };

            return(View("UpdateFlight", model));
        }
        public async Task StartScraperAsync(QueryOptions query)
        {
            try
            {
                var collectedData = new List <FlightDataModel>();
                var getRequest    = new HttpRequestMessage(HttpMethod.Get, GetUri(query));
                var htmlDocument  = await client.GetHtmlDocumentAsync(getRequest);

                var departingFlights = ParseFlightTable(htmlDocument, "//div[@id='avaday-outbound-result']//table[@class='avadaytable']/tbody");

                // change query for each flight to update taxes, look if it is possible to not do that..
                Regex flightRegex = new Regex(@"\d\|([A-Za-z0-9]+)\|(\d)\|");
                foreach (var fl in departingFlights)
                {
                    Match match = flightRegex.Match(fl.CheapestFare.Type);
                    if (match.Success)
                    {
                        query.DepFlight   = match.Groups[1].Value;
                        query.DepFareType = match.Groups[2].Value;

                        getRequest = new HttpRequestMessage(HttpMethod.Get, GetUri(query));
                        var nextDocument = await client.GetHtmlDocumentAsync(getRequest);

                        DateTime dep = query.DepDate + ParseTime(fl.DepTime);
                        DateTime arr = query.DepDate + ParseTime(fl.ArrTime);
                        decimal  tax = GetTaxData(nextDocument);

                        var flightData = new FlightDataModel
                        {
                            Departure  = fl.Departure,
                            Arrival    = fl.Arrival,
                            Connection = fl.Connection,
                            DepTime    = dep,
                            ArrTime    = arr,
                            Price      = fl.CheapestFare.Price,
                            Taxes      = tax
                        };

                        collectedData.Add(flightData);
                    }
                }

                //on return fl
                if (query.IsReturnTrip)
                {
                    throw new NotImplementedException("Return fl info collection not implemented");
                    // var returnFlights = ParseFlightTable(htmlDocument, "//div[@id='avaday-inbound-result']//table[@class='avadaytable']/tbody");
                    //same as dep
                    //collect taxes info
                    //write to new data
                }

                disk.SaveCollectedData(collectedData);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Error encounted while parsing date {0:yyyy/MM/dd} \"{1}\"", query.DepDate, e.Message);
                System.Console.WriteLine(e.StackTrace);
            }
        }
        public async Task <IActionResult> Edit(string id, FlightDataModel flightDataModel)
        {
            if (id != flightDataModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(flightDataModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FlightDataModelExists(flightDataModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(flightDataModel));
        }
Exemplo n.º 7
0
        public async Task Delete(int id)
        {
            FlightDataModel existingFlight =
                await _appDbContext.Flights.Where(a => a.Id == id)
                .FirstOrDefaultAsync();

            _appDbContext.Entry(existingFlight).State = EntityState.Deleted;
            await _appDbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> Create(FlightDataModel flightDataModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(flightDataModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(flightDataModel));
        }
Exemplo n.º 9
0
        public async Task UpdateFlight(int id, Flight flight)
        {
            FlightDataModel existingFlight =
                await _appDbContext.Flights.Where(a => a.Id == id)
                .FirstOrDefaultAsync();

            existingFlight.DepartureAirportId   = flight.DepartureAirport.Id;
            existingFlight.DestinationAirportId = flight.DestinationAirport.Id;
            existingFlight.Distance             = flight.Distance;
            existingFlight.FuelConsumption      = flight.FuelConsumption;
            existingFlight.FlightTime           = flight.FlightTime;
            existingFlight.TakeoffEffort        = flight.TakeoffEffort;

            _appDbContext.Entry(existingFlight).State = EntityState.Modified;
            await _appDbContext.SaveChangesAsync();
        }
        public async Task <IActionResult> Create(FlightDataModel flightDataModel)
        {
            if (flightDataModel.DepatureTime > flightDataModel.ArrivalTime)
            {
                ModelState.AddModelError("ArrivalTime", "Arrival time cannot be earlier than departure time!");
                ModelState.AddModelError("DepatureTime", "Departure Time cannot be later than arrival time!");
            }
            if (ModelState.IsValid)
            {
                _context.Add(flightDataModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(flightDataModel));
        }
Exemplo n.º 11
0
        public async Task <int> EnterFlight(Flight flight)
        {
            FlightDataModel newFlight = new FlightDataModel()
            {
                DepartureAirportId   = flight.DepartureAirport.Id,
                DestinationAirportId = flight.DestinationAirport.Id,
                Distance             = flight.Distance,
                FuelConsumption      = flight.FuelConsumption,
                FlightTime           = flight.FlightTime,
                TakeoffEffort        = flight.TakeoffEffort
            };

            await _appDbContext.Flights.AddAsync(newFlight);

            await _appDbContext.SaveChangesAsync();

            return(newFlight.Id);
        }
Exemplo n.º 12
0
        public IActionResult Index()
        {
            var airportsData        = _db.Airports.ToList();
            var airportsMonthlyData = _db.AirportsMonthlyData.ToList();
            var airportGroupedData  = Data.GetGroupedData(airportsData);

            FlightDataModel fdm = new FlightDataModel
            {
                AirportsData       = Data.GetAirports(airportsData, airportsMonthlyData),
                AirportMonthlyData = airportsMonthlyData,
                GroupedData        = airportGroupedData
            };

            ViewBag.Years = FlightStatistics.Models.Data.GetYears();

            ViewBag.AirportMonthlyData = airportsMonthlyData;
            ViewBag.GroupedData        = airportGroupedData;
            return(View(fdm));
        }
Exemplo n.º 13
0
        public ActionResult AddFlight(FlightDataModel flightDataModel)
        {
            if (ModelState.IsValid)
            {
                var flight = CollectRawData(flightDataModel);

                var result = _flightService.Crete(flight);
                if (result.Status == AnswerStatus.Success)
                {
                    return(RedirectToAction("AddFlight"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        if (error.Key == "Number error")
                        {
                            ModelState.AddModelError("flightDataModel.Number", error.Value);
                        }

                        if (error.Key == "Date error")
                        {
                            ModelState.AddModelError("flight.ArrivalDate", error.Value);
                        }

                        ModelState.AddModelError(error.Key, error.Value);
                    }
                }
            }

            var cities         = _cityService.GetAll().Result;
            var members        = GetMemberCollection(flightDataModel);
            var lodededMembers = _aircrewMemberService.FindByIds(members.Select(x => x.Id)).Result;

            var model = new FlightCreateUpdateModel()
            {
                Cities                 = cities,
                FlightDataModel        = flightDataModel,
                CurrentAircrewMemebers = lodededMembers
            };

            return(View("AddFlight", model));
        }