public void UpdateField(Field currentField)
        {
            var locationField = currentField as LocationField;
            if (locationField != null)
            {
                var date = ObjectContext.CurrentUserAccount().Now().Date;
                var recurringService = ObjectContext.RecurringServices.First(rs => rs.Id == locationField.ServiceTemplateId);
                if (recurringService != null)
                {
                    var routeTasks = ObjectContext.RouteTasks.Where(rt => rt.RecurringServiceId != null && rt.RecurringServiceId == recurringService.Id && rt.Date >= date).Include(rt => rt.RouteDestination).ToArray();
                    foreach (var routeTask in routeTasks)
                    {
                        routeTask.LocationId = locationField.LocationId;
                        
                        if (routeTask.RouteDestination != null)
                            routeTask.RouteDestination.LocationId = locationField.LocationId;
                    }
                    var services = ObjectContext.Services.Where(s => s.RecurringServiceId == recurringService.Id).Select(s => s.Id).ToArray();

                    var fields = ObjectContext.Fields.Where(f => f.ServiceTemplateId.HasValue && services.Contains(f.ServiceTemplateId.Value)
                                                                && f.ParentFieldId == locationField.Id);

                    foreach (LocationField field in fields)
                        field.Value = locationField.Value;

                    ObjectContext.SaveChanges();
                }
            }

            this.ObjectContext.Fields.AttachAsModified(currentField);
        }
        public void InsertField(Field field)
        {
            if ((field.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(field, EntityState.Added);
            }
            else
            {
                this.ObjectContext.Fields.AddObject(field);
            }

            var serviceTemplate = ObjectContext.ServiceTemplates.FirstOrDefault(st => st.Id == field.OwnerServiceTemplate.Id);

            //When adding a FoundOPS level service template to a service provider propogate the template/fields to all the Clients
            if (serviceTemplate != null && serviceTemplate.ServiceTemplateLevel == ServiceTemplateLevel.ServiceProviderDefined)
            {
                //In order to propagate the original Template added must already be saved
                ObjectContext.SaveChanges();
                ObjectContext.CommandTimeout = 600;

                ObjectContext.PropagateNewFields(field.Id, CurrentUserAccount().Id);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Fields EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToFields(Field field)
 {
     base.AddObject("Fields", field);
 }
        public void DeleteField(Field field)
        {
            var serviceTemplate = ObjectContext.ServiceTemplates.FirstOrDefault(st => st.Id == field.ServiceTemplateId);

            //If the associated ServiceTemplate is on the ServiceProvider level, delete the field and all children
            if (serviceTemplate != null && serviceTemplate.ServiceTemplateLevel == ServiceTemplateLevel.ServiceProviderDefined)
            {
                ObjectContext.DeleteFieldAndChildrenBasedOnFieldId(field.Id);
                return;
            }

            var loadedField = this.ObjectContext.Fields.FirstOrDefault(f => f.Id == field.Id);
            if (loadedField != null) this.ObjectContext.Detach(loadedField);

            if ((field.EntityState == EntityState.Detached))
                this.ObjectContext.Fields.Attach(field);

            if (field as OptionsField != null)
            {
                this.DeleteOptionsField((OptionsField)field);
                return;
            }

            field.ChildrenFields.Load();
            //Delete children
            foreach (var child in field.ChildrenFields.ToArray())
                DeleteField(child);

            this.ObjectContext.Fields.DeleteObject(field);
        }
Esempio n. 5
0
 /// <summary>
 /// Create a new Field object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="required">Initial value of the Required property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 public static Field CreateField(global::System.Guid id, global::System.String name, global::System.Boolean required, global::System.DateTime createdDate)
 {
     Field field = new Field();
     field.Id = id;
     field.Name = name;
     field.Required = required;
     field.CreatedDate = createdDate;
     return field;
 }