Ejemplo n.º 1
0
        protected TEntity CreateSummaryEntity <TEntity, TEntityDetails>(Guid summaryId, TEntityDetails details, EntityConstructor <TEntity> constructor,
                                                                        Action <TSummary, TEntity> add)
            where TEntityDetails : IPublicSafetyEntityDetails
            where TEntity : PublicSafetyEntity
        {
            var summary = UnitOfWork.Find <TSummary>(summaryId);

            RequireViewPermissions(summary.AgencyId, SummaryModule);

            var entity = constructor(summary.AgencyId, details.Id);

            details.MapInto(entity);
            add(summary, entity);
            _masterIndexService.ProcessMasterIndexes(entity);

            UnitOfWork.Commit();

            // TODO: Hack until the Surrogate Keys are introduced in the Data layer.
            // TODO: Currently the Event messages will get the wrong Id unless they are raised AFTER the database commit
            // TODO: because the database may override the Guid the Domain is trying to use.
            UnitOfWork.PendingMessages.Add(DataEntryMessages.EntityCreated(entity, SummaryModule, DataEntryAggregateType.Summary));
            UnitOfWork.PublishPendingMessages();

            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transfer a Report into its Summary.
        /// </summary>
        public virtual TSummary Begin()
        {
            // Check the Number
            if (string.IsNullOrWhiteSpace(Report.Number))
            {
                throw new Exception("Reports cannot be transfered without a valid number!");
            }

            // Find the Report's Summary in the Agency using the Report Number.
            var summary = UnitOfWork.GetEntityQuery <TSummary>()
                          .FirstOrDefault(x => x.AgencyId == Report.AgencyId &&
                                          x.Number == Report.Number);

            if (!string.IsNullOrWhiteSpace(Report.CaseNumber))
            {
                ParentCase = GetOrCreateParentCase();
            }

            // Copy data into the existing or new summary.
            var update = summary != null;

            // automapper doesn't aggregate the collections
            var s = update ? _UpdateSummary(summary) : Report.MapInto(_CreateSummary(Report));

            // Process Master Indexes
            _masterIndexService.ProcessMasterIndexes(s);

            // Commit the Work
            UnitOfWork.Commit();

            // TODO: Hack until the Surrogate Keys are introduced in the Data layer.
            // TODO: Currently the messages may get the wrong Id unless they are raised AFTER the database commit
            // TODO: because the database may override the Guid the Domain is trying to use.
            PublishSummaryMessages(s, update ? EventOperation.Update : EventOperation.Create, Report.Id);

            UnitOfWork.PublishPendingMessages();

            return(s);
        }