Inheritance: BaseEntity
Exemplo n.º 1
0
        public bool Delete(Classifier entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Classifier> repo = uow.GetRepository<Classifier>();
                entity = repo.Reload(entity);

                //delete the Classifier
                repo.Delete(entity);

                // commit changes
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return (true);
        }
Exemplo n.º 2
0
        public Classifier Create(string name, string description, Classifier parent)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Ensures(Contract.Result<Classifier>() != null && Contract.Result<Classifier>().Id >= 0);

            Classifier u = new Classifier()
            {
                Name = name,
                Description = description,
                Parent = parent, // if parent is null, current node will be a root
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Classifier> repo = uow.GetRepository < Classifier>();
                repo.Put(u);
                uow.Commit();
            }
            return (u);
        }
Exemplo n.º 3
0
        public bool AddChild(Classifier end1, Classifier end2)
        {
            Contract.Requires(end1 != null && end1.Id >= 0);
            Contract.Requires(end2 != null && end2.Id >= 0);

            bool result = false;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Classifier> repo = uow.GetRepository<Classifier>();

                end1 = repo.Reload(end1);
                repo.LoadIfNot(end1.Children);
                if (!end1.Children.Contains(end2))
                {
                    end1.Children.Add(end2);
                    end2.Parent = end1;
                    uow.Commit();
                    result = true;
                }
            }
            return (result);
        }
Exemplo n.º 4
0
        public DataAttribute CreateDataAttribute(string shortName, string name, string description, bool isMultiValue, bool isBuiltIn, string scope, MeasurementScale measurementScale, DataContainerType containerType, string entitySelectionPredicate,
            DataType dataType, Unit unit, Methodology methodology, Classifier classifier,
            ICollection<AggregateFunction> functions, ICollection<GlobalizationInfo> globalizationInfos, ICollection<Constraint> constraints,
            ICollection<ExtendedProperty> extendedProperies
            )
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(shortName));
            Contract.Requires(dataType != null && dataType.Id >= 0);
            Contract.Requires(unit != null && unit.Id >= 0);

            Contract.Ensures(Contract.Result<DataAttribute>() != null && Contract.Result<DataAttribute>().Id >= 0);
            DataAttribute e = new DataAttribute()
            {
                ShortName = shortName,
                Name = name,
                Description = description,
                IsMultiValue = isMultiValue,
                IsBuiltIn = isBuiltIn,
                Scope = scope,
                MeasurementScale = measurementScale,
                ContainerType = containerType,
                EntitySelectionPredicate = entitySelectionPredicate,
                DataType = dataType,
                Unit = unit,
                Methodology = methodology,
                AggregateFunctions = functions,
                GlobalizationInfos = globalizationInfos,
                Constraints = constraints,
                ExtendedProperties = extendedProperies,
            };
            if (classifier != null && classifier.Id > 0)
                e.Classification = classifier;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<DataAttribute> repo = uow.GetRepository<DataAttribute>();
                repo.Put(e);
                uow.Commit();
            }
            return (e);
        }
Exemplo n.º 5
0
        public Classifier Update(Classifier entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID");

            Contract.Ensures(Contract.Result<Classifier>() != null && Contract.Result<Classifier>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<Classifier> repo = uow.GetRepository<Classifier>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
            }
            return (entity);
        }