Beispiel #1
0
        private long SaveRoute(CalculationManager.Node destination, forsendelse rute, pakke pakke)
        {
            if (destination.Previous == null)
            {
                rute.pakke = pakke;
                rute.StartBy = destination.By.CityId;
                return DataManager.OpretRute(rute);
            }

            if (rute.SlutBy == null)
                rute.SlutBy = destination.By.CityId;

            var sd = destination.Previous.Ruter.FirstOrDefault(p => p.From == destination.Previous && p.To == destination);

            var forsendelse = new forsendelsesRute();
            forsendelse.StartBy = destination.Previous.By.CityId;
            forsendelse.SlutBy = destination.By.CityId;
            forsendelse.Price = Convert.ToUInt32(sd.Route.Pris);
            forsendelse.TransportTime = sd.Route.Rute.Time;
            forsendelse.TransportType = (Int64)sd.Route.TransportType;

            rute.forsendelsesRute.Add(forsendelse);

            return SaveRoute(destination.Previous, rute, pakke);
        }
Beispiel #2
0
 public void printRute(CalculationManager.Node n)
 {
     if (n.Previous != null)
         printRute(n.Previous);
     Debug.WriteLine("By: {0}, Duration: {1}",n.By.Name, n.Distance);
 }
Beispiel #3
0
 public RouteManager(IList<IExternalServicesApi> externalApis)
 {
     _externalApis = externalApis;
     _calculationManager = new CalculationManager();
 }
        public GetRoutesContract GetRoute(
            [FromUri] int id, 
            DateTime date,
            string measurements,
            double weight, 
            string requirements = null)
        {
            var routesResult = new GetRoutesContract();
            List<RouteDTO> routes = new List<RouteDTO>();
            try
            {
                var splittedMeasurements = measurements.Split('x');

                var depth = (int) Convert.ToDouble(splittedMeasurements[0]);
                var width = (int) Convert.ToDouble(splittedMeasurements[1]);
                var height = (int) Convert.ToDouble(splittedMeasurements[2]);
                var package = new pakke
                {
                    SizeDepth = depth,
                    SizeWidth = width,
                    SizeHight = height,
                    Weight = (int)(weight * 1000),
                    forsendelse = new List<forsendelse>
                    {
                        new forsendelse
                        {
                            AfsendelsesDato = date,
                            forsendelsesType = GetForsendelsesType(requirements)
                        }
                    }
                };
                var ruter = DataManager.HentRuter(new @by {CityId = id});

                var calculationManager = new CalculationManager();

                var forsendelsesTyper = GetForsendelsesType(requirements).Select(x => x.packetTypeId.Value).ToList();

                if (!forsendelsesTyper.Any())
                {
                    forsendelsesTyper = new List<long>() { Int32.MaxValue };
                }
                var multiplier = DataManager.HentPakkeType(forsendelsesTyper);

                routes = new List<RouteDTO>();
                foreach (var route in ruter)
                {
                    routes.Add(new RouteDTO
                    {
                        destination = route.Rute.EndCity,
                        duration = route.Rute.Time,
                        price = 100 * Convert.ToInt32(calculationManager.BeregnPris(package, multiplier))
                    });
                }
            }
            catch (Exception)
            {

            }

            routesResult.Routes = routes;
            return routesResult;
        }