示例#1
0
        public string GetAirlines(string text)
        {
            string result = "";

            result = CommonHeppler.GetAirlines(text);

            return(result);
        }
示例#2
0
        public ActionResult GetAirport(string text)
        {
            object result = null;

            result = CommonHeppler.GetAirport(text);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
示例#3
0
        public ActionResult CheckDirctFlightPost(string FlightNumber, string Date)
        {
            // testing
            Claim c = null;
            Guid  g = new Guid("ecbc3e69-71c0-4fab-971d-3acc3bd98480");

            using (AirHelpDBContext dc = new AirHelpDBContext())
            {
                c = dc.Claims.Where(cl => cl.ClaimId == g).SingleOrDefault();


                ViewBag.IsEu         = c.AirPorts.Any(a => CommonHeppler.IsEuCountry(a.countryCode));
                ViewBag.delayMessage = (c.issueDistance < 1500000 ? "Полета ви закъсня ли с повече от 2 часа?" :
                                        (c.issueDistance < 3500000 || ViewBag.IsEu ? "Полета ви закъсня ли с повече от 3 часа?" : "Полета ви закъсня ли с повече от 3 часа ?"));
            }
            return(View("ColectData", c));

            var model = new VMDirectFlight()
            {
                date        = Date,
                number      = FlightNumber,
                numberError = ""
            };
            var arr  = Date.Split('.');
            var day  = int.Parse(arr[0]);
            var mont = int.Parse(arr[1]);
            var year = int.Parse(arr[2]);

            FlightStatus fligth = CommonHeppler.GetFlight(FlightNumber, Date);

            if (fligth.flightStatuses.Length == 0)
            {
                model.commonError = "Невалидна комбинция от номер и дата на полета";
                return(View("DirectFlight", model));
            }

            var AirLine = fligth.appendix.airlines.ToList().Find(a => a.iata == fligth.flightStatuses[0].primaryCarrierFsCode);

            Claim claim = new Claim
            {
                ClaimId           = Guid.NewGuid(),
                FlightDate        = Date,
                State             = ClaimStatus.Accepted,
                UserId            = User.Identity.IsAuthenticated ? User.Identity.Name : null,
                DateCreated       = DateTime.Now,
                Type              = ProblemType.Pending,
                FlightNumber      = FlightNumber,
                AirCompany        = AirLine.name,
                AirCompanyCountry = ""
            };

            int number = 0;

            fligth.appendix.airports.ToList().ForEach(a =>
            {
                double distance = 0;
                if (number > 0)
                {
                    var sCoord = new GeoCoordinate(fligth.appendix.airports[number - 1].longitude, fligth.appendix.airports[number - 1].latitude);
                    var eCoord = new GeoCoordinate(fligth.appendix.airports[number].longitude, fligth.appendix.airports[number].latitude);

                    distance = sCoord.GetDistanceTo(eCoord);
                }
                AirPort airport = new AirPort
                {
                    Id             = Guid.NewGuid(),
                    ap_name        = a.name,
                    city           = a.city,
                    cityCode       = a.cityCode,
                    country        = a.countryName,
                    countryCode    = a.countryCode,
                    elevation      = a.elevationFeet,
                    iata           = a.iata,
                    number         = number,
                    name           = a.name,
                    timezone       = 0,
                    icao           = a.icao,
                    type           = "",
                    x              = a.latitude,
                    y              = a.longitude,
                    distanceToNext = distance
                };
                number++;
                claim.AirPorts.Add(airport);
            });

            claim.allDistance = claim.AirPorts.Sum(a => a.distanceToNext);

            using (AirHelpDBContext dc = new AirHelpDBContext())
            {
                dc.Claims.Add(claim);
                dc.SaveChanges();
            }

            return(View("ColectData", claim));
        }
示例#4
0
        public string GetFlight(string number, string date)
        {
            var flight = CommonHeppler.GetFlight(number, date);

            return(flight.ToString());
        }
示例#5
0
        public ActionResult ColectFlightDataFlightPost()
        {
            Guid newGuid = Guid.NewGuid();

            var jsonString         = Request.Form["jsonAirport"];
            var jsonAirCompany     = Request.Form["jsonAirComapany"];
            var issueDepartureCode = Request.Form["Flight"];
            var nubmer             = Request.Form["FlightNumber"];
            var nubmers            = Request.Form["FlightNumbers"];
            var date  = Request.Form["Date"];
            var dates = Request.Form["Dates"];

            string[] flightNumbers = nubmers != null?nubmers.Split(',') : new string[]
            {
                nubmer, ""
            };
            string[] flightDates = dates != null?dates.Split(',') : new string[]
            {
                date, ""
            };

            var json = new JavaScriptSerializer();

            Airport[] airports   = json.Deserialize <Airport[]>(jsonString);
            Airline   airCompany = json.Deserialize <Airline>(jsonAirCompany);

            Claim claim = new Claim
            {
                ClaimId           = Guid.NewGuid(),
                State             = ClaimStatus.Pending,
                UserId            = null,
                DateCreated       = DateTime.Now,
                Type              = ProblemType.Pending,
                AirCompany        = airCompany.name,
                AirCompanyCountry = airCompany.country,
                AirCompanyCode    = airCompany.iata
            };

            if (issueDepartureCode == null)
            {
                issueDepartureCode = airports[0].iata;
            }

            int number = 1;

            airports.ToList().ForEach(a =>
            {
                AirPort airport = new AirPort
                {
                    Id           = Guid.NewGuid(),
                    ap_name      = a.ap_name,
                    city         = a.city,
                    country      = a.country,
                    elevation    = int.Parse(a.elevation),
                    iata         = a.iata,
                    number       = number,
                    name         = a.name,
                    timezone     = 0,
                    icao         = "",
                    type         = "",
                    x            = double.Parse(a.x),
                    y            = double.Parse(a.y),
                    FlightNumber = airports.Length == number ? (nubmer != null ? nubmer : "") : flightNumbers[number - 1],
                    FlightDate   = airports.Length == number ? (date != null ? date : "") : flightDates[number - 1],
                    startIssue   = (number == 1 && airports.Length == 2) || (a.iata == issueDepartureCode)
                };
                number++;
                claim.AirPorts.Add(airport);
            });

            double allDistance   = 0;
            double issuDistance  = 0;
            bool   flag          = false;
            var    claimAirPorts = claim.AirPorts.ToArray();

            for (int i = 0; i < claimAirPorts.Length - 1; i++)
            {
                var sCoord = new GeoCoordinate(claimAirPorts[i].y, claimAirPorts[i].x);
                var eCoord = new GeoCoordinate(claimAirPorts[i + 1].y, claimAirPorts[i + 1].x);

                var d = sCoord.GetDistanceTo(eCoord);
                claimAirPorts[i].distanceToNext = d;
                allDistance += d;
                flag         = flag || (claimAirPorts[i].iata == issueDepartureCode);
                if (flag)
                {
                    issuDistance += d;
                }
            }

            claim.issueDistance = issuDistance;
            claim.allDistance   = allDistance;

            // Check EU flagth
            IsEUFlight isEUFlight = IsEUFlight.NonEU;

            if (claim.AirPorts.All(a => CommonHeppler.IsEuCountryByName(a.country)))
            {
                isEUFlight = IsEUFlight.EU;
            }
            else if (claim.AirPorts.Any(a => CommonHeppler.IsEuCountryByName(a.country)))
            {
                isEUFlight = IsEUFlight.EUMixed;
            }

            double distance = (claim.Type == ProblemType.Delay) ? claim.allDistance : claim.issueDistance;

            FlightType flightType = FlightType.NotSupported;

            if (isEUFlight == IsEUFlight.NonEU)
            {
                flightType = FlightType.NotSupported;
            }
            else if (distance <= 1500000)
            {
                flightType = FlightType.F1500;
            }
            else if (distance <= 3500000 || isEUFlight == IsEUFlight.EU)
            {
                flightType = FlightType.FTo3500;
            }
            else
            {
                flightType = FlightType.FmoreThen3500;
            }

            claim.IsEUFlight = isEUFlight;
            claim.FlightType = flightType;

            using (AirHelpDBContext dc = new AirHelpDBContext())
            {
                dc.Claims.Add(claim);
                dc.SaveChanges();
            }

            return(View("ColectData", claim));
        }