Ejemplo n.º 1
0
        /// <summary>
        /// Creates a route from a service template and date. Uses a random route name.
        /// </summary>
        private void CreateRoute(DateTime date, ServiceTemplate serviceTemplate, BusinessAccount ownerBusinessAccount, int clientIndex)
        {
            var newRoute = new Route
            {
                Id = Guid.NewGuid(),
                Name = _routeNames.RandomItem(),
                Date = date.Date,
                RouteType = serviceTemplate.Name,
                OwnerBusinessAccount = ownerBusinessAccount,
                CreatedDate = DateTime.UtcNow,
                LastModified = DateTime.UtcNow
            };

            //Add employees to the Route
            newRoute.Employees.Add(_employeesDesignData.DesignEmployees.FirstOrDefault(e => e.FirstName == "Jon"));

            //Add vehicles to the Route
            newRoute.Vehicles.Add(_vehiclesDesignData.DesignVehicles.RandomItem());

            var orderInRoute = 1;

            var startingClientIndex = clientIndex * 6;

            //Create Services and RouteTasks, add them to the Route
            for (var i = startingClientIndex; i <= (startingClientIndex + 5); i++)
            {
                //Prevents you from trying to add a client that doesnt exist in Design Data
                if (i > _clientsDesignData.DesignClients.Count())
                    break;

                var currentClient = _clientsDesignData.DesignClients.ElementAt(i);

                //Take the first location from the client
                var currentLocation = currentClient.Locations.ElementAt(0);

                var newService = new Service
                {
                    ServiceDate = newRoute.Date,
                    ServiceTemplate = serviceTemplate.MakeChild(ServiceTemplateLevel.ServiceDefined),
                    Client = currentClient,
                    ServiceProvider = ownerBusinessAccount,
                    CreatedDate = DateTime.UtcNow,
                    LastModified = DateTime.UtcNow
                };

                newService.ServiceTemplate.SetDestination(currentLocation);

                var routeTask = new RouteTask
                {
                    OrderInRouteDestination = 1,
                    Date = newRoute.Date,
                    Location = currentClient.Locations.ElementAt(0),
                    Client = currentClient,
                    Name = newRoute.RouteType,
                    EstimatedDuration = new TimeSpan(0, _random.Next(25), 0),
                    OwnerBusinessAccount = ownerBusinessAccount,
                    Service = newService,
                    TaskStatus = ownerBusinessAccount.TaskStatuses.FirstOrDefault(ts => ts.DefaultTypeInt != null && ts.DefaultTypeInt == ((int)StatusDetail.RoutedDefault)),
                    CreatedDate = DateTime.UtcNow,
                    LastModified = DateTime.UtcNow
                };

                var routeDestination = new RouteDestination
                {
                    OrderInRoute = orderInRoute,
                    CreatedDate = DateTime.UtcNow,
                    LastModified = DateTime.UtcNow
                };
                routeDestination.RouteTasks.Add(routeTask);
                newRoute.RouteDestinations.Add(routeDestination);

                orderInRoute++;
            }

            DesignRoutes.Add(newRoute);
        }