/// <summary>
        /// Deletes the Route and it's RouteDestinations.
        /// It does not delete the route destination's tasks.
        /// Although they are automatically removed through cascading.
        /// </summary>
        /// <param name="route"></param>
        public void DeleteRoute(Route route)
        {
            this.ObjectContext.DetachExistingAndAttach(route);

            //route.Employees.Load();
            //route.Employees.Clear();

            //route.Vehicles.Load();
            //route.Vehicles.Clear();

            route.RouteDestinations.Load();
            foreach (var routeDestination in route.RouteDestinations.ToArray())
                DeleteRouteDestination(routeDestination);

            this.ObjectContext.Routes.DeleteObject(route);
        }
        public void UpdateRoute(Route route)
        {
            route.LastModified = DateTime.UtcNow;
            route.LastModifyingUserId = CurrentUserAccount().Id;

            this.ObjectContext.Routes.AttachAsModified(route);
        }
        public void InsertRoute(Route route)
        {
            route.Date = route.Date.Date; //Remove any time
            route.StartTime = route.StartTime.SetDate(route.Date); //Set to same date as route.Date
            route.EndTime = route.EndTime.SetDate(route.Date); //Set to same date as route.Date

            if ((route.EntityState != EntityState.Detached))
                this.ObjectContext.ObjectStateManager.ChangeObjectState(route, EntityState.Added);
            else
                this.ObjectContext.Routes.AddObject(route);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns whether the route is included in the current filter.
        /// </summary>
        /// <param name="route">The route to check.</param>
        /// <returns></returns>
        public bool RouteIncludedInFilter(Route route)
        {
            //Selects all the Region's names from the RouteTasks in the Route
            var regionsForRoute = route.RouteDestinations.SelectMany(rd => rd.RouteTasks.Where(rt => rt.Location != null && rt.Location.Region != null)
                .Select(rt => rt.Location.Region.Name)).ToArray();

            var meetsRouteTypeFilter = ServiceTemplateOptions.Any(option => option.IsSelected && ((ServiceTemplate)option.Entity).Name == route.RouteType);

            //Only filter by region if there are locations or locations with regions in the route
            var meetsRegionsFilter = !regionsForRoute.Any() || !RegionOptions.Any() || 
                RegionOptions.Any(option => option.IsSelected && regionsForRoute.Contains(((Region)option.Entity).Name));

            return meetsRouteTypeFilter && meetsRegionsFilter;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Create a new Route object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="startTime">Initial value of the StartTime property.</param>
 /// <param name="endTime">Initial value of the EndTime property.</param>
 /// <param name="ownerBusinessAccountId">Initial value of the OwnerBusinessAccountId property.</param>
 /// <param name="routeType">Initial value of the RouteType property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 public static Route CreateRoute(global::System.Guid id, global::System.DateTime date, global::System.DateTime startTime, global::System.DateTime endTime, global::System.Guid ownerBusinessAccountId, global::System.String routeType, global::System.DateTime createdDate)
 {
     Route route = new Route();
     route.Id = id;
     route.Date = date;
     route.StartTime = startTime;
     route.EndTime = endTime;
     route.OwnerBusinessAccountId = ownerBusinessAccountId;
     route.RouteType = routeType;
     route.CreatedDate = createdDate;
     return route;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Routes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRoutes(Route route)
 {
     base.AddObject("Routes", route);
 }