示例#1
0
        /// <summary>
        /// Adds the dragged item to route task.
        /// </summary>
        /// <param name="destination">The destination.</param>
        /// <param name="routeTask">The route task.</param>
        /// <param name="dropPlacement">The drop placement.</param>
        public static void AddToRouteTask(RouteTask destination, RouteTask routeTask, DropPlacement dropPlacement)
        {
            var destinationRouteTask = destination;

            var placeInDestination = destinationRouteTask.OrderInRouteDestination;

            //Makes adjustments to the placeInDestination based on where routeTask is being dropped
            if (dropPlacement == DropPlacement.After)
                placeInDestination++;

            if (dropPlacement == DropPlacement.Before && placeInDestination > 0)
                placeInDestination--;

            //Add the RouteTask to the RouteDestination found above
            destinationRouteTask.RouteDestination.RouteTasksListWrapper.Insert(placeInDestination, routeTask);
        }
        public void RouteTasksEntityAddedComposite(RouteTask routeTask)
        {
            //If this RouteDestination does not already have a Location update it with the task's location
            if (this.Location == null)
            {
                if (routeTask.Location != null)
                    this.Location = routeTask.Location;
            }

            //If this RouteDestination does not already have a Client update it with the task's client
            if (this.Client == null && routeTask.Location != null)
            {
                if (routeTask.Location.Client != null)
                    this.Client = routeTask.Location.Client;
            }
        }
 public void DeleteRouteTask(RouteTask routeTask)
 {
     this.ObjectContext.DetachExistingAndAttach(routeTask);
     this.ObjectContext.RouteTasks.DeleteObject(routeTask);
 }
        public void UpdateRouteTask(RouteTask currentRouteTask)
        {
            var original = this.ObjectContext.RouteTasks.Include("Service").First(rt => rt.Id == currentRouteTask.Id);
            this.ObjectContext.Detach(original);

            //User changes date of a route task in the task board
            if (original.Date != currentRouteTask.Date)
            {
                var service = this.ObjectContext.Services.FirstOrDefault(s => s.Id == original.ServiceId);

                if (service != null)
                    service.ServiceDate = currentRouteTask.Date;

                var recurringService = this.ObjectContext.RecurringServices.FirstOrDefault(rs => rs.Id == original.RecurringServiceId)
                                            ?? this.ObjectContext.RecurringServices.FirstOrDefault(rs => rs.Id == service.RecurringServiceId.Value);

                if (recurringService != null)
                {
                    var excludedDates = recurringService.ExcludedDates.ToList();
                    excludedDates.Add(original.Date);
                    recurringService.ExcludedDates = excludedDates;
                    recurringService.LastModified = DateTime.UtcNow;
                    recurringService.LastModifyingUserId = CurrentUserAccount().Id;

                    //If there wasnt previously a saved Service, make one. Otherwise, the service will get lost
                    if (service == null)
                    {
                        //Generate new service
                        var newService = new Service
                        {
                            ServiceDate = currentRouteTask.Date,
                            ClientId = recurringService.ClientId,
                            RecurringServiceId = recurringService.Id,
                            ServiceProviderId = recurringService.Client.BusinessAccount.Id,
                            ServiceTemplate = recurringService.ServiceTemplate.MakeChild(ServiceTemplateLevel.ServiceDefined),
                            CreatedDate = DateTime.UtcNow,
                            LastModified = DateTime.UtcNow,
                            LastModifyingUserId = CurrentUserAccount().Id
                        };
                        newService.Id = newService.ServiceTemplate.Id;

                        //Add the RouteTask to the Service
                        newService.RouteTasks.Add(currentRouteTask);

                        ObjectContext.Services.AddObject(newService);
                    }
                }

                //Set original date on the route task
                //Used in sql function to generate route tasks for the day
                currentRouteTask.OriginalDate = original.Date;
            }

            currentRouteTask.LastModified = DateTime.UtcNow;
            currentRouteTask.LastModifyingUserId = CurrentUserAccount().Id;

            this.ObjectContext.RouteTasks.AttachAsModified(currentRouteTask);
        }
        public void InsertRouteTask(RouteTask routeTask)
        {
            routeTask.Date = routeTask.Date.Date; //Remove any time

            if ((routeTask.EntityState != EntityState.Detached))
                this.ObjectContext.ObjectStateManager.ChangeObjectState(routeTask, EntityState.Added);
            else
                this.ObjectContext.RouteTasks.AddObject(routeTask);
        }
示例#6
0
        /// <summary>
        /// Returns whether the routeTask is included in the current filter.
        /// </summary>
        /// <param name="routeTask">The routeTask to check.</param>
        /// <returns></returns>
        public bool RouteTaskIncludedInFilter(RouteTask routeTask)
        {
            var meetsRouteTypeFilter = ServiceTemplateOptions.Any(option => option.IsSelected && ((ServiceTemplate)option.Entity).Name == routeTask.Name);
            var meetsRegionsFilter = routeTask.Location == null || routeTask.Location.Region == null || !RegionOptions.Any() ||
                RegionOptions.Any(option => (option.IsSelected && routeTask.Location.Region.Name == ((Region)option.Entity).Name));

            return meetsRouteTypeFilter && meetsRegionsFilter;
        }
        /// <summary>
        /// Goes through each routeTask and removes it from route destinations
        /// Delete any route destinations without remaining tasks.
        /// </summary>
        /// <param name="routeTasksToDelete"></param>
        private void DeleteRouteTasks(RouteTask[] routeTasksToDelete)
        {
            //If no RouteTasks exist, return
            if (!routeTasksToDelete.Any()) return;

            foreach (var routeTask in routeTasksToDelete)
            {
                routeTask.RouteDestinationReference.Load();
                var routeDestination = routeTask.RouteDestination;

                //Remove the RouteTask from the RouteDestination
                if (routeDestination != null)
                {
                    routeDestination.RouteTasks.Load();
                    routeTask.RouteDestination = null;

                    //If the RouteDestination has no remaining tasks, delete it
                    if (routeDestination.RouteTasks.Count == 0)
                        DeleteRouteDestination(routeDestination);
                }

                //Delete the route task
                this.ObjectContext.DetachExistingAndAttach(routeTask);
            }
        }
示例#8
0
 /// <summary>
 /// Create a new RouteTask object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="businessAccountId">Initial value of the BusinessAccountId property.</param>
 /// <param name="estimatedDuration">Initial value of the EstimatedDuration property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="statusInt">Initial value of the StatusInt property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="orderInRouteDestination">Initial value of the OrderInRouteDestination property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 public static RouteTask CreateRouteTask(global::System.Guid id, global::System.Guid businessAccountId, global::System.TimeSpan estimatedDuration, global::System.String name, global::System.Int32 statusInt, global::System.DateTime date, global::System.Int32 orderInRouteDestination, global::System.DateTime createdDate)
 {
     RouteTask routeTask = new RouteTask();
     routeTask.Id = id;
     routeTask.BusinessAccountId = businessAccountId;
     routeTask.EstimatedDuration = estimatedDuration;
     routeTask.Name = name;
     routeTask.StatusInt = statusInt;
     routeTask.Date = date;
     routeTask.OrderInRouteDestination = orderInRouteDestination;
     routeTask.CreatedDate = createdDate;
     return routeTask;
 }
示例#9
0
 /// <summary>
 /// Deprecated Method for adding a new object to the RouteTasks EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRouteTasks(RouteTask routeTask)
 {
     base.AddObject("RouteTasks", routeTask);
 }
示例#10
0
        /// <summary>
        /// Adds the draggedItem to either the Route or RouteDestination it was dragged to.
        /// </summary>
        /// <param name="routeTask">The route task.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="placeInRoute">The place in route.</param>
        /// <param name="dropPlacement"> </param>
        public static void AddRouteTaskToDestinationOrRoute(RouteTask routeTask, object destination, int placeInRoute, DropPlacement dropPlacement)
        {
            //If the user drops the task on a destination, just add it to the end of its list of RouteTasks
            if ((destination is RouteDestination) && dropPlacement == DropPlacement.In)
            {
                ((RouteDestination)destination).RouteTasksListWrapper.Add(routeTask);
                //TODO:add analytic

                //No need to do any of the other logic below, skip to the next iteration of the loop
                return;
            }

            routeTask.RemoveRouteDestination();

            //Create new destination
            var newDestination = new RouteDestination
            {
                Id = Guid.NewGuid(),
                LocationId =  routeTask.LocationId,
                ClientId = routeTask.ClientId
            };

            //Add the tasks to the destination
            newDestination.RouteTasks.Add(routeTask);

            if (destination is RouteDestination)
            {
                //Get the Destinations, Route
                var route = ((RouteDestination)destination).Route;

                //Add the new destination to the Route
                route.RouteDestinationsListWrapper.Insert(placeInRoute, newDestination);
                //TODO:add analytic
            }
            if (destination is Route)
            {
                //Add the new destination to the Route
                ((Route)destination).RouteDestinationsListWrapper.Insert(placeInRoute, newDestination);
                //TODO:add analytic
            }
        }
示例#11
0
        /// <summary>
        /// Regenerate a RouteTask and add it to the TaskBoard
        /// </summary>
        /// <param name="routeTask">The RouteTask to regenerate and add to the TaskBoard</param>
        public static void AddRouteTaskToTaskBoard(RouteTask routeTask)
        {
            if (((ObservableCollection<RouteTask>)VM.TaskBoard.CollectionView.SourceCollection).Contains(routeTask))
                return;

            var statuses = VM.Routes.TaskStatusesForBusinessAccount;

            var createdStatus = statuses.FirstOrDefault(ts => ts.DefaultTypeInt == ((int) StatusDetail.CreatedDefault));

            routeTask.TaskStatus = createdStatus;
            
            ((ObservableCollection<RouteTask>)VM.TaskBoard.CollectionView.SourceCollection).Add(routeTask);
        }
示例#12
0
        /// <summary>
        /// Adds the route task to a route in the correct destination. This also redirects to another method which will actually add it to the correct place
        /// </summary>
        /// <param name="routeTask">The route task.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="placeInRoute">The place in route.</param>
        /// <param name="dropPlacement">The drop placement.</param>
        public static void AddRouteTaskToRoute(RouteTask routeTask, object destination, int placeInRoute, DropPlacement dropPlacement)
        {
            //Set RouteTask's Status to Routed
            //routeTask.Status = Status.Routed;

            //IF the drag destination is a RouteTask, add the draggedItem to that RouteTask
            var routeTaskDestination = destination as RouteTask;

            if (routeTaskDestination != null)
            {
                AddToRouteTask(routeTaskDestination, routeTask, dropPlacement);
                //TODO:add analytic

                //No need to do any of the other logic below, skip to the next iteration of the loop
                return;
            }

            AddRouteTaskToDestinationOrRoute(routeTask, destination, placeInRoute, dropPlacement);
            //TODO:add analytic
        }