public ServiceTemplate MakeChild(ServiceTemplateLevel level)
        {
#if !SILVERLIGHT
            var serviceTemplateChild = new ServiceTemplate
            {
                Id = Guid.NewGuid(),
                Name = this.Name,
                ParentServiceTemplate = this,
                ServiceTemplateLevel = level,
                CreatedDate = DateTime.UtcNow
            };

            if (serviceTemplateChild.ServiceTemplateLevel == ServiceTemplateLevel.ServiceProviderDefined)
                serviceTemplateChild.OwnerServiceProvider = this.OwnerServiceProvider;

            if (serviceTemplateChild.ServiceTemplateLevel == ServiceTemplateLevel.ClientDefined)
                serviceTemplateChild.OwnerClient = this.OwnerClient;

            if (serviceTemplateChild.ServiceTemplateLevel == ServiceTemplateLevel.RecurringServiceDefined)
                serviceTemplateChild.OwnerRecurringService = this.OwnerRecurringService;

            if (serviceTemplateChild.ServiceTemplateLevel == ServiceTemplateLevel.ServiceDefined)
                serviceTemplateChild.OwnerService = this.OwnerService;

            foreach (var field in this.Fields.ToArray())
                serviceTemplateChild.Fields.Add(field.MakeChild());

            //TODO: Uncomment.
            //if (this.Invoice != null)
            //{
            //    serviceTemplateChild.Invoice = this.Invoice.MakeChild();
            //    serviceTemplateChild.Invoice.Id = serviceTemplateChild.Id;
            //}

            return serviceTemplateChild;
#else
            var serviceTemplateChild = MakeChildSilverlight(level);

            //TODO: Uncomment.
            //if (this.Invoice != null)
            //{
            //    serviceTemplateChild.Invoice = this.Invoice.MakeChild();
            //    serviceTemplateChild.Invoice.Id = serviceTemplateChild.Id;
            //}

            return serviceTemplateChild;
#endif
        }
        /// <summary>
        /// This will only be used for FoundOPS level service templates. Editing name is disabled for lower service templates, for now.
        /// Name changes on FoundOPS level service templates should propogate to all children.
        /// </summary>
        /// <param name="currentServiceTemplate"></param>
        public void UpdateServiceTemplate(ServiceTemplate currentServiceTemplate)
        {
            if (currentServiceTemplate.ServiceTemplateLevel != ServiceTemplateLevel.FoundOpsDefined)
                throw new Exception("Should this ever happen?");

            this.ObjectContext.ServiceTemplates.AttachAsModified(currentServiceTemplate);

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

            ObjectContext.SaveChanges();

            ObjectContext.PropagateNameChange(currentServiceTemplate.Id, CurrentUserAccount().Id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceTemplate"></param>
        public void InsertServiceTemplate(ServiceTemplate serviceTemplate)
        {
            if (serviceTemplate.ServiceTemplateLevel != ServiceTemplateLevel.FoundOpsDefined && serviceTemplate.OwnerServiceTemplateId == null)
                throw new Exception("All service templates (besides FoundOPS levels) should have a parent.");

            if ((serviceTemplate.EntityState != EntityState.Detached))
            {
                this.ObjectContext.ObjectStateManager.ChangeObjectState(serviceTemplate, EntityState.Added);
            }
            else
            {
                this.ObjectContext.ServiceTemplates.AddObject(serviceTemplate);
            }

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

                ObjectContext.PropagateNewServiceTemplateToClients(serviceTemplate.Id, CurrentUserAccount().Id);
            }
        }
        /// <summary>
        /// Deletes the service template and its invoice, fields, and children service templates
        /// </summary>
        /// <param name="serviceTemplate"></param>
        public void DeleteServiceTemplate(ServiceTemplate serviceTemplate)
        {
            //change timeout from 30 to 600 to prevent timeout
            ObjectContext.CommandTimeout = 600;

            //Stored procedure that will find all the children of this ServiceTemplate
            //Then it will delete all of them
            //Cascades will take care of all associations
            ObjectContext.DeleteServiceTemplateAndChildrenBasedOnServiceTemplateId(serviceTemplate.Id);
        }
        /// <summary>
        /// Compares two service templates to see if one is an ancestor of the other.
        /// </summary>
        /// <param name="a">One service template to compare.</param>
        /// <param name="b">The other service template to compare.</param>
        public static bool ServiceTemplateIsAncestorOrDescendent(ServiceTemplate a, ServiceTemplate b)
        {
            //Climb the parents of x and see if an ancestor is y
            var currentServiceTemplate = a;
            while (currentServiceTemplate != null)
            {
                if (currentServiceTemplate == b)
                    return true;

                currentServiceTemplate = currentServiceTemplate.ParentServiceTemplate;
            }

            //Climb the parents of y and see if an ancestor is x
            currentServiceTemplate = b;
            while (currentServiceTemplate != null)
            {
                if (currentServiceTemplate == a)
                    return true;

                currentServiceTemplate = currentServiceTemplate.ParentServiceTemplate;
            }

            return false;
        }
Esempio n. 6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ServiceTemplates EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToServiceTemplates(ServiceTemplate serviceTemplate)
 {
     base.AddObject("ServiceTemplates", serviceTemplate);
 }
Esempio n. 7
0
 /// <summary>
 /// Create a new ServiceTemplate object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="levelInt">Initial value of the LevelInt property.</param>
 /// <param name="createdDate">Initial value of the CreatedDate property.</param>
 public static ServiceTemplate CreateServiceTemplate(global::System.Guid id, global::System.Int16 levelInt, global::System.DateTime createdDate)
 {
     ServiceTemplate serviceTemplate = new ServiceTemplate();
     serviceTemplate.Id = id;
     serviceTemplate.LevelInt = levelInt;
     serviceTemplate.CreatedDate = createdDate;
     return serviceTemplate;
 }