Ejemplo n.º 1
0
        /// <summary>
        /// Aggiunge una nuova DocumentUnitAggregate
        /// </summary>
        /// <param name="aggregate"></param>
        /// <returns>Ritorna l'aggregato aggiunto</returns>
        public DocumentUnitAggregate UdsAddDocumentUnitAggregate(DocumentUnitAggregate aggregate)
        {
            try
            {
                if (aggregate == null)
                {
                    throw DocumentUnitAggregateException.NotFound();
                }

                var entity = new Model.DocumentUnitAggregate
                {
                    IdAggregate      = Guid.NewGuid(),
                    AggregationType  = aggregate.AggregationType,
                    CloseDate        = aggregate.CloseDate,
                    PreservationDate = aggregate.PreservationDate,
                    XmlFascicle      = aggregate.XmlFascicle
                };

                this.db.DocumentUnitAggregate.AddObject(entity);
                if (requireSave)
                {
                    this.db.SaveChanges();
                }

                var ret = entity.Convert(0, 3);
                return(ret);
            }
            finally
            {
                Dispose();
            }
        }
Ejemplo n.º 2
0
        private Model.DocumentUnitAggregate UdsTryEditDocumentUnitAggregate(Guid idAggregate)
        {
            bool isReadOnly;
            bool isPreserved;

            var aggregate = UdsGetDocumentUnitAggregateModel(idAggregate, out isReadOnly, out isPreserved);

            if (isReadOnly)
            {
                throw DocumentUnitAggregateException.ReadOnly();
            }

            return(aggregate);
        }
Ejemplo n.º 3
0
        private Model.DocumentUnitAggregate UdsGetDocumentUnitAggregateModel(Guid idAggregate, out bool isReadOnly, out bool isPreserved)
        {
            isReadOnly  = false;
            isPreserved = false;

            var aggregate = this.db.DocumentUnitAggregate
                            .Include("DocumentUnit")
                            .SingleOrDefault(p => p.IdAggregate == idAggregate);

            if (aggregate == null)
            {
                throw DocumentUnitAggregateException.NotFound();
            }

            isReadOnly  = (aggregate.CloseDate != null || aggregate.PreservationDate != null);
            isPreserved = aggregate.PreservationDate != null;

            return(aggregate);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Apre a modifiche una DocumentUnit e le relative Aggregate a meno che una queste non sia già stata Preservata
        /// </summary>
        /// <param name="idDocumentUnit"></param>
        public DocumentUnit UdsOpenDocumentUnit(Guid idDocumentUnit)
        {
            bool isReadOnly;
            bool isPreserved;

            var docUnit = UdsGetDocumentUnitModel(idDocumentUnit, out isReadOnly, out isPreserved);

            //già aperta
            if (!isReadOnly)
            {
                return(docUnit.Convert());
            }

            //preservata, non si può fare
            if (isPreserved)
            {
                throw DocumentUnitAggregateException.Preserved();
            }

            //apre la unit
            docUnit.CloseDate = null;

            //apre gli aggregaati
            var aggregates = UdsGetUnitAggregates(docUnit.IdDocumentUnit);

            foreach (var aggregate in aggregates)
            {
                aggregate.CloseDate = null;
            }

            if (requireSave)
            {
                this.db.SaveChanges();
            }

            return(docUnit.Convert());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Apre una DocumentUnitAggregate a meno che una queste non sia già stata Preservata e tutte le relative DocumentUnit
        /// </summary>
        /// <param name="idDocumentUnit"></param>
        public DocumentUnitAggregate UdsOpenDocumentUnitAggregate(Guid idAggregate)
        {
            bool isReadOnly;
            bool isPreserved;

            var aggregate = UdsGetDocumentUnitAggregateModel(idAggregate, out isReadOnly, out isPreserved);

            //già aperta
            if (!isReadOnly)
            {
                return(aggregate.Convert());
            }

            //preservata, non si può fare
            if (isPreserved)
            {
                throw DocumentUnitAggregateException.Preserved();
            }

            //apre la unit
            aggregate.CloseDate = null;

            //apre le units
            var units = UdsGetAggregateChain(aggregate.IdAggregate);

            foreach (var unit in units)
            {
                unit.CloseDate = null;
            }

            if (requireSave)
            {
                this.db.SaveChanges();
            }

            return(aggregate.Convert());
        }