public void DeleteRecurringService(RecurringService recurringService)
 {
     ObjectContext.DeleteRecurringService(recurringService.Id);
 }
        public void UpdateRecurringService(RecurringService currentRecurringService)
        {
            //If there is a newly added excluded date today or in the future. Remove any associated route tasks for that date
            var originalRecurringService = ChangeSet.GetOriginal(currentRecurringService);

            var user = ObjectContext.CurrentUserAccount();

            var date = user.Now().Date;

            var newlyAddedFutureDatesToExclude = currentRecurringService.ExcludedDates.Except(originalRecurringService.ExcludedDates).Where(d => d >= date).ToArray();
            if (newlyAddedFutureDatesToExclude.Any())
            {
                var routeTasksToDelete = this.ObjectContext.RouteTasks.Where(rt =>
                    rt.RecurringServiceId == currentRecurringService.Id && newlyAddedFutureDatesToExclude.Contains(rt.Date)).ToArray();

                var servicesToDelete = routeTasksToDelete.Select(rt => rt.Service);

                DeleteRouteTasks(routeTasksToDelete);

                DeleteServices(servicesToDelete);
            }

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

            this.ObjectContext.RecurringServices.AttachAsModified(currentRecurringService);
        }
 public void InsertRecurringService(RecurringService recurringService)
 {
     if ((recurringService.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(recurringService, EntityState.Added);
     }
     else
     {
         this.ObjectContext.RecurringServices.AddObject(recurringService);
     }
 }
        /// <summary>
        /// Called when the parent RecurringService's details are loaded.
        /// </summary>
        /// <param name="recurringService">The loaded recurring service parent for this ServiceHolder.</param>
        public void OnLoadRecurringServiceDetails(RecurringService recurringService)
        {
            ClearPreviouslyLoadedDetails();

            var generatedService = recurringService.GenerateServiceOnDate(OccurDate);
            generatedService.ParentServiceHolder = this;

            _entityGraph = generatedService.EntityGraph();

            //Detach the generated service. Then manually add it to the DomainContext if there are changes
            Manager.Data.DetachEntities(_entityGraph);

            //Track the generated service's entity changes manually because it is detached
            _entityGraph.PropertyChanged += IfChangesAddToDomainContext;
            generatedService.PropertyChanged += OnSaveConvertToExistingService;
            Manager.CoreDomainContext.ChangesRejected += OnRejectChangedReloadDetails;

            Service = generatedService;
            DetailsLoaded = true;
        }
 /// <summary>
 /// Create a new RecurringService object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="clientId">Initial value of the ClientId property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 public static RecurringService CreateRecurringService(global::System.Guid id, global::System.Guid clientId, global::System.DateTime createdDate)
 {
     RecurringService recurringService = new RecurringService();
     recurringService.Id = id;
     recurringService.ClientId = clientId;
     recurringService.CreatedDate = createdDate;
     return recurringService;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the RecurringServices EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToRecurringServices(RecurringService recurringService)
 {
     base.AddObject("RecurringServices", recurringService);
 }