Esempio n. 1
0
        public IActionResult RouteDeliveries(int?id)
        {
            Route           route      = driver.Routes.Where(r => r.ID == id).FirstOrDefault();
            List <Delivery> deliveries = route.Deliveries.ToList();
            List <DriverDeliveryViewModel> modelsList = new List <DriverDeliveryViewModel>();

            foreach (Delivery delivery in deliveries)
            {
                DriverDeliveryViewModel model = new DriverDeliveryViewModel();
                model.ClientName = delivery.Client.FirstName + " " + delivery.Client.LastName;
                model.DeliverBy  = delivery.DeliverBy;

                string deliverytatusString = StatusExtension.DisplayName(delivery.DeliveryStatus.Status);
                if (delivery.DeliveryStatus.Status.Equals(Status.Delivered))
                {
                    DateTime deliveredDate = delivery.DeliveryStatus.DeliveredDate.Value;
                    deliverytatusString += " " + deliveredDate.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
                }
                else if (delivery.DeliveryStatus.Status.Equals(Status.FailedDelivery))
                {
                    deliverytatusString = "Failed, reason: " + delivery.DeliveryStatus.ReasonFailed;
                }

                model.DeliveryStatusString = deliverytatusString;
                model.ID             = delivery.ID;
                model.ItemSizeString = ItemSizeDimensionsExtension.getItemDimensionsBasedOnSize(delivery.ItemSize).ToString();
                model.ItemWeight     = delivery.ItemWeight;
                model.ClientAddress  = delivery.Client.Address;
                modelsList.Add(model);
            }
            return(View(modelsList));
        }
        private DriverAssignmentResult getCostForDriverBeingAssignedToRoute(Driver driver, Route route, DateTime DeliverBy)
        {
            double profit = 0;
            DriverAssignmentResult result = new DriverAssignmentResult(route.ID, route.DeliverBy, driver);

            if (driverIsOnHoliday(driver, DeliverBy))
            {
                result.AssignmentProfit = 0;
                return(result);
            }
            //if there is already a delivery on a day before deliveryby day
            if (driver.Routes.Where(r => r.DeliverBy.Equals(DeliverBy.AddDays(-1))).ToList().Count() != 0)
            {
                // return 0; //ifdriver is not available on a day, no need to check other
                result.AssignmentProfit = 0;
                return(result);
            }
            else
            {
                profit += 5;
            }

            double weightOfDeliveriesInRoute = 0;
            double capacityOfBoxes           = 0;

            for (int i = 0; i < route.Deliveries.Count(); i++)
            {
                Delivery delivery = route.Deliveries.ElementAt(i);
                weightOfDeliveriesInRoute += delivery.ItemWeight;
                capacityOfBoxes           += calculateCapacity(ItemSizeDimensionsExtension.getItemDimensionsBasedOnSize(delivery.ItemSize));
            }

            Vehicle suitableVehicle = null;

            for (int i = 0; i < driver.Vehicles.Count(); i++)
            {
                Vehicle vehicle = driver.Vehicles.ElementAt(i);
                if (capacityOfBoxes <= calculateCapacity(new DeliveryItemDimensions(vehicle.Height, vehicle.Width, vehicle.Length)) && vehicle.MaxLoad >= weightOfDeliveriesInRoute)
                {
                    suitableVehicle = vehicle;
                    break;
                }
            }

            //add 0 weight if there is no
            if (suitableVehicle == null)
            {
                result.AssignmentProfit = 0;
                return(result);
                //if no vehicle available then no point looking further
            }
            else
            {
                result.Vehicle = suitableVehicle;
                profit        += 5;
            }
            var distanceFromDepotLocation = locationService.getDistanceBetweenTwoAddresses(driver.Address, route.PickUpAddress).Result;

            profit += 100 / distanceFromDepotLocation;
            result.AssignmentProfit = profit;
            return(result);
        }