Esempio n. 1
0
        public ActionResult Create(Flight flight)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    flight.Flight_id = Guid.NewGuid().ToString();

                    var DepartureCoord = _flightService.GetCoordinate(flight.Departure);

                    var DestinationCoord = _flightService.GetCoordinate(flight.Destination);

                    var Distance = DistanceCalculService.CalculDistance(DepartureCoord[0],
                                                                        DepartureCoord[1], DestinationCoord[0], DestinationCoord[1]);


                    flight.Distance = (decimal?)Distance / 1000;


                    flight.FuelConsumption = (decimal?)FuelCalculService.FuelCalculation(Distance / 1000);


                    _flightService.CreateFlight(flight);

                    //ViewBag.Departure = _flightService.GetAllAirportNames();

                    return(RedirectToAction("Index"));
                }
                return(View(flight));
            }
            catch
            {
                return(View());
            }
        }
        public void GetCoordinateTest2()
        {
            IFlightRepository repo     = new FlightRepository();
            IFlightServices   Business = new FlightServices(repo);
            double            res      = 0;

            res = DistanceCalculService.CalculDistance(repo.GetAirportById(10).Latitude,
                                                       repo.GetAirportById(10).Longitude, repo.GetAirportById(11).Latitude,
                                                       repo.GetAirportById(11).Longitude);

            res = res / 1000;

            res = Math.Round(res, 4);

            Assert.AreEqual(9290, 7951, res);
        }
        public void DistanceCalculServicesTest1()
        {
            IFlightRepository repo     = new FlightRepository();
            IFlightServices   Business = new FlightServices(repo);
            double            res      = 0;

            res = DistanceCalculService.CalculDistance(repo.GetAirportById(1).Latitude,
                                                       repo.GetAirportById(1).Longitude, repo.GetAirportById(2).Latitude,
                                                       repo.GetAirportById(2).Longitude);

            res = res / 1000;

            res = Math.Round(res, 4);

            Assert.AreEqual(5900.0513, res);
        }