Пример #1
0
        public void ApplyProperties(ISupportDefaultPropertyValues DefaultPropertyObject, ISupportPropertyValues DomainObjectInstance)
        {
            if (DefaultPropertyObject == null)
            {
                throw new ArgumentNullException("The DefaultPropertyObject parameter can not be null");
            }

            if (DomainObjectInstance == null)
            {
                throw new ArgumentNullException("The DomainObjectInstance parameter can not be null");
            }

            if (!ValidateDomainObjectInstance(DomainObjectInstance))
            {
                throw new PropertiesAlreadyAssignedExistException(DomainObjectInstance.Name);
            }

            // var trans = persistor.GetTransaction(DomainObjectInstance.Id);

            foreach (DefaultPropertyValue item in DefaultPropertyObject.DefaultPropertyValues)
            {
                PropertyValue propValue = item.CreatePropertyValue();

                //  trans.Save(propValue);

                try
                {
                    DomainObjectInstance.AddPropertyValue(propValue);
                }
                catch (Exception ex)
                {
                    throw new PropertyValueException(string.Format("Exception adding PropertyValue {0} to domain object {1}", item.Name, DomainObjectInstance.Name), ex);
                }
            }

            if (DomainObjectInstance is IHasTemplate)
            {
                DomainObjectInstance.As <IHasTemplate>().TemplateId = DefaultPropertyObject.Id;
            }

            //trans.Save(DomainObjectInstance);

            //OperationReport report = persistor.ProcessCommandsTransaction(trans);

            //if (!report.Success)
            //{
            //    Exception ex = null;
            //    if (report.ExceptionCount > 0)
            //    {
            //        ex = report.Exceptions.First();
            //    }
            //    throw new PropertyValueException(string.Format("Exception persisting PropertyValue to the db for {0} domain object", DomainObjectInstance.Name), ex);
            //}
        }
Пример #2
0
 private void CreateAndAssignPropertyValue(ISupportPropertyValues dynamicPropertyObject, DefaultPropertyValue propertyDefValue)
 {
     dynamicPropertyObject.AddPropertyValue(propertyDefValue.CreatePropertyValue());
 }