public RS.ResourceStructureAttribute CreateResourceStructureAttribute(string name, string description)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(!String.IsNullOrWhiteSpace(description));

            using (DataTypeManager dataTypeManager = new DataTypeManager())
            {
                DataType type = dataTypeManager.Repo.Get(p => p.SystemType.Equals("String")).FirstOrDefault();
                if (type == null)
                {
                    type = dataTypeManager.Create("String", "string", TypeCode.String);
                }

                RS.ResourceStructureAttribute resourceStrucAtt = new RS.ResourceStructureAttribute()
                {
                    Name        = name,
                    Description = description,
                    DataType    = type,
                };


                using (IUnitOfWork uow = this.GetUnitOfWork())
                {
                    IRepository <RS.ResourceStructureAttribute> repo = uow.GetRepository <RS.ResourceStructureAttribute>();
                    repo.Put(resourceStrucAtt);
                    uow.Commit();
                }

                return(resourceStrucAtt);
            }
        }
Ejemplo n.º 2
0
        public static ResourceStructureAttributeModel Convert(RS.ResourceStructureAttribute attribute)
        {
            DomainConstraint dc = (DomainConstraint)attribute.Constraints.Where(p => p.GetType().Equals(typeof(DomainConstraint)));

            return(new ResourceStructureAttributeModel()
            {
                AttributeId = attribute.Id,
                AttributeName = attribute.Name,
                AttributeDescription = attribute.Description,
                //Constraints = attribute.Constraints.ToList()
                DomainConstraint = new DomainConstraintModel(dc)
            });
        }
        public bool DeleteResourceStructureAttribute(RS.ResourceStructureAttribute resourceStrucAtt)
        {
            Contract.Requires(resourceStrucAtt != null);
            Contract.Requires(resourceStrucAtt.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <RS.ResourceStructureAttribute> repoAttr = uow.GetRepository <RS.ResourceStructureAttribute>();
                repoAttr.Delete(resourceStrucAtt);
                uow.Commit();
            }

            return(true);
        }
        public RS.ResourceStructureAttribute UpdateResourceStructureAttribute(RS.ResourceStructureAttribute resourceStructureAttribute)
        {
            Contract.Requires(resourceStructureAttribute != null);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <RS.ResourceStructureAttribute> repo = uow.GetRepository <RS.ResourceStructureAttribute>();
                repo.Merge(resourceStructureAttribute);
                var merged = repo.Get(resourceStructureAttribute.Id);
                repo.Put(merged);
                uow.Commit();
            }

            return(resourceStructureAttribute);
        }
        public RS.ResourceAttributeUsage CreateResourceAttributeUsage(RS.ResourceStructureAttribute rsa, RS.ResourceStructure rs, bool isOptional, bool isFileDataType)
        {
            RS.ResourceAttributeUsage resourceAttributeUsage = new RS.ResourceAttributeUsage()
            {
                Label                      = rsa.Name,
                ResourceStructure          = rs,
                ResourceStructureAttribute = rsa,
                IsValueOptional            = isOptional,
                IsFileDataType             = isFileDataType
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <RS.ResourceAttributeUsage> repo = uow.GetRepository <RS.ResourceAttributeUsage>();
                repo.Put(resourceAttributeUsage);
                uow.Commit();
            }

            return(resourceAttributeUsage);
        }
        public ResourceStructureAttributeUsageModel(long usageId, long resourceAttributeId, string parentName)
        {
            UsageId             = usageId;
            ResourceAttributeId = resourceAttributeId;

            //set Parent if exsits
            if (parentName != null)
            {
                ParentAttributeName = parentName;
            }
            else
            {
                ParentAttributeName = "";
            }

            using (ResourceStructureAttributeManager rsaManager = new ResourceStructureAttributeManager())
            {
                ResourceAttributeUsage usage = rsaManager.GetResourceAttributeUsageById(usageId);

                IsValueOptional = usage.IsValueOptional;
                IsFileDataType  = usage.IsFileDataType;

                RS.ResourceStructureAttribute attr = rsaManager.GetResourceStructureAttributesById(resourceAttributeId);

                foreach (Constraint constraint in attr.Constraints)
                {
                    if (constraint is DomainConstraint)
                    {
                        DomainConstraint dc = (DomainConstraint)constraint;
                        dc.Materialize();
                        DomainConstraint = new DomainConstraintModel(dc);
                    }
                }

                ResourceAttributeName        = attr.Name;
                ResourceAttributeDescription = attr.Description;
            }
        }