Exemplo n.º 1
0
        private DossierFolderRole CreateDossierFolderRole(DossierFolderRole entity, DossierFolder dossierFolder, Role role)
        {
            DossierFolderRole dossierFolderRole = null;

            if (role != null)
            {
                dossierFolderRole = new DossierFolderRole
                {
                    Role                  = role,
                    DossierFolder         = dossierFolder,
                    AuthorizationRoleType = AuthorizationRoleType.Accounted,
                    Status                = DossierRoleStatus.Active,
                    IsMaster              = true
                };

                _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(dossierFolder.Dossier, dossierFolder, DossierLogType.FolderAuthorize,
                                                                                                        string.Concat("Autorizzata la cartella '", dossierFolder.Name, "' al settore '", role.Name, "' (", role.EntityShortId, ") per competenza (Accounted)"), CurrentDomainUser.Account));

                if (dossierFolder.Fascicle != null && !_unitOfWork.Repository <FascicleRole>().ExistFascicleRolesAccounted(dossierFolder.Fascicle.UniqueId, role.EntityShortId))
                {
                    CreateFascicleRole(dossierFolder, dossierFolderRole.AuthorizationRoleType, role);
                }
            }
            return(dossierFolderRole);
        }
Exemplo n.º 2
0
        private void DeleteFascicleRole(DossierFolderRole item, Guid?actualIdFascicle)
        {
            short        roleId              = item.Role.EntityShortId;
            string       roleName            = item.Role.Name;
            FascicleRole currentFascicleRole = null;

            if (actualIdFascicle.HasValue && (currentFascicleRole = _unitOfWork.Repository <FascicleRole>().GetFascicleRoleAccounted(actualIdFascicle.Value, roleId).SingleOrDefault()) != null)
            {
                _unitOfWork.Repository <FascicleLog>().Insert(FascicleService.CreateLog(currentFascicleRole.Fascicle, FascicleLogType.Authorize,
                                                                                        $"Rimossa autorizzazione '{currentFascicleRole.AuthorizationRoleType}' al settore {roleName} ({roleId})", CurrentDomainUser.Account));

                _unitOfWork.Repository <FascicleRole>().Delete(currentFascicleRole);
            }
        }
Exemplo n.º 3
0
        protected override Process BeforeUpdate(Process entity, Process entityTransformed)
        {
            entityTransformed.ProcessType = ProcessType.Defined;
            if (entity.Category != null)
            {
                entityTransformed.Category = _unitOfWork.Repository <Category>().Find(entity.Category.EntityShortId);
            }

            if (entity.Roles != null)
            {
                foreach (Role item in entityTransformed.Roles.Where(f => !entity.Roles.Any(c => c.EntityShortId == f.EntityShortId)).ToList())
                {
                    foreach (DossierFolder df in entityTransformed.Dossier.DossierFolders)
                    {
                        if (df.DossierFolderRoles.Count() != 0)
                        {
                            DossierFolderRole role = df.DossierFolderRoles.FirstOrDefault(x => x.Role.EntityShortId == item.EntityShortId);
                            if (role != null)
                            {
                                _unitOfWork.Repository <DossierFolderRole>().Delete(role);
                                _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.DELETE, string.Concat("Rimosso il settore '", item.Name, "' da volumi '", df.Name, "'"), typeof(TenantConfiguration).Name, CurrentDomainUser.Account));
                            }
                        }

                        if (df.FascicleTemplates.Count() != 0)
                        {
                            foreach (ProcessFascicleTemplate pft in df.FascicleTemplates)
                            {
                                if (pft.JsonModel != null && !String.IsNullOrEmpty(pft.JsonModel))
                                {
                                    Fascicle     fascicle = JsonConvert.DeserializeObject <Fascicle>(pft.JsonModel);
                                    FascicleRole role     = fascicle.FascicleRoles.FirstOrDefault(x => x.Role.EntityShortId == item.EntityShortId);
                                    if (role != null && role.IsMaster)
                                    {
                                        fascicle.FascicleRoles.Remove(role);
                                        pft.JsonModel = JsonConvert.SerializeObject(fascicle);
                                        _unitOfWork.Repository <ProcessFascicleTemplate>().Update(pft);
                                        _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.DELETE, string.Concat("Rimosso il settore '", item.Name, "' da modello di fascicolo '", pft.Name, "'"), typeof(TenantConfiguration).Name, CurrentDomainUser.Account));
                                    }
                                }
                            }
                        }
                    }

                    entityTransformed.Roles.Remove(item);
                    _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.DELETE, string.Concat("Rimosso il settore '", item.Name, "'"), typeof(TenantConfiguration).Name, CurrentDomainUser.Account));
                }
                foreach (Role item in entity.Roles.Where(f => !entityTransformed.Roles.Any(c => c.EntityShortId == f.EntityShortId)))
                {
                    foreach (DossierFolder df in entityTransformed.Dossier.DossierFolders)
                    {
                        DossierFolderRole role = new DossierFolderRole
                        {
                            Role = _unitOfWork.Repository <Role>().Find(item.EntityShortId),
                            AuthorizationRoleType = AuthorizationRoleType.Accounted,
                            IsMaster      = true,
                            DossierFolder = _unitOfWork.Repository <DossierFolder>().Find(df.UniqueId),
                            Status        = DossierRoleStatus.Active
                        };

                        if (!df.DossierFolderRoles.Any(x => x.Role.EntityId == item.EntityShortId))
                        {
                            _unitOfWork.Repository <DossierFolderRole>().Insert(role);
                            _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.INSERT, string.Concat("Aggiunto il settore '", item.Name, "' da volumi '", df.Name, "'"), typeof(TenantConfiguration).Name, CurrentDomainUser.Account));
                        }
                    }
                    entityTransformed.Roles.Add(_unitOfWork.Repository <Role>().Find(item.EntityShortId));
                    _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.INSERT, string.Concat("Aggiunto il settore '", item.Name, "'"), typeof(TenantConfiguration).Name, CurrentDomainUser.Account));
                }
            }

            _unitOfWork.Repository <TableLog>().Insert(TableLogService.CreateLog(entityTransformed.UniqueId, null, TableLogEvent.UPDATE, $"Modificata raccolta dei procedimenti {entity.Name} con ID {entity.UniqueId}", typeof(Process).Name, CurrentDomainUser.Account));

            return(base.BeforeUpdate(entity, entityTransformed));
        }
Exemplo n.º 4
0
        protected override DossierFolder BeforeUpdate(DossierFolder entity, DossierFolder entityTransformed)
        {
            if (CurrentUpdateActionType.HasValue && CurrentUpdateActionType == Common.Infrastructures.UpdateActionType.CloneProcessDetails)
            {
                _unitOfWork.Repository <DossierFolder>().ExecuteProcedure(CommonDefinition.SQL_SP_DossierFolder_UpdateHierarchy,
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_IdDossier, entity.Dossier.UniqueId));
                entityTransformed.JsonMetadata = null;
                entityTransformed.Name         = entity.Name.Substring(2, entity.Name.Length - 2);
                return(base.BeforeUpdate(entity, entityTransformed));
            }

            bool hasFascicle = entityTransformed.Fascicle != null;

            entityTransformed.Status = DossierFolderStatus.InProgress;

            if (_unitOfWork.Repository <DossierFolder>().CountChildren(entity.UniqueId) > 0)
            {
                entityTransformed.Status = DossierFolderStatus.Folder;
            }

            Guid?actualIdFascicle = entityTransformed.Fascicle == null ? null : new Guid?(entityTransformed.Fascicle.UniqueId);

            entityTransformed.Fascicle = null;

            if (entity.Dossier != null)
            {
                entityTransformed.Dossier = _unitOfWork.Repository <Dossier>().Find(entity.Dossier.UniqueId);
            }

            if (entity.Category != null)
            {
                entityTransformed.Category = _unitOfWork.Repository <Category>().Find(entity.Category.EntityShortId);
            }

            if (entity.Fascicle != null)
            {
                entityTransformed.Fascicle = _unitOfWork.Repository <Fascicle>().Find(entity.Fascicle.UniqueId);
                entityTransformed.Status   = DossierFolderStatus.Fascicle;
                CreateOrUpdateFolderHystoryLog(entityTransformed);
                entityTransformed.Name = string.Concat(entityTransformed.Fascicle.Title, "-", entityTransformed.Fascicle.FascicleObject);
                _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, entityTransformed, DossierLogType.FolderModify,
                                                                                                        string.Concat("Aggiornata la cartella '", entityTransformed.Name, "' con fascicolo associato '", entityTransformed.Fascicle.Title, "-", entityTransformed.Fascicle.FascicleObject, "'"), CurrentDomainUser.Account));
            }

            if (CurrentUpdateActionType.HasValue && CurrentUpdateActionType == Common.Infrastructures.UpdateActionType.DossierFolderAuthorizationsPropagation)
            {
                _unitOfWork.Repository <DossierFolder>().ExecuteProcedure(CommonDefinition.SQL_SP_DossierFolder_PropagateAtuthorizationToDescendants,
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_IdParent, entity.UniqueId),
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_IdDossier, entity.Dossier.UniqueId),
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_AuthorizationType, AuthorizationRoleType.Accounted),
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_AuthorizationTypeDescription, AuthorizationRoleType.Accounted.ToString()),
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_RegistrationUser, CurrentDomainUser.Account),
                                                                          new QueryParameter(CommonDefinition.SQL_Param_DossierFolder_System, Environment.MachineName));

                UpdateHashLog(entityTransformed);
            }

            if (entityTransformed.Fascicle == null && hasFascicle)
            {
                foreach (DossierFolderRole item in entityTransformed.DossierFolderRoles.ToList())
                {
                    DeleteFascicleRole(item, actualIdFascicle);
                }

                DossierLog    logDossier          = _unitOfWork.Repository <DossierLog>().GetFolderHystoryLog(entityTransformed.UniqueId).SingleOrDefault();
                DossierFolder oldEntity           = logDossier == null ? null : JsonConvert.DeserializeObject <DossierFolder>(logDossier.LogDescription, DefaultJsonSerializer);
                string        previousFascileName = string.Copy(entityTransformed.Name);
                if (oldEntity != null)
                {
                    entityTransformed.Name = string.IsNullOrEmpty(oldEntity.Name) ? "Cartella vuota" : oldEntity.Name;
                }
                _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, entityTransformed, DossierLogType.FolderFascicleRemove,
                                                                                                        string.Concat("Aggiornata la cartella '", entityTransformed.Name, "' con rimozione del fascicolo '", previousFascileName, "'"), CurrentDomainUser.Account));
            }

            if (entity.DossierFolderRoles != null)
            {
                foreach (DossierFolderRole item in entityTransformed.DossierFolderRoles.Where(f => !entity.DossierFolderRoles.Any(c => c.UniqueId == f.UniqueId)).ToList())
                {
                    _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, entityTransformed, DossierLogType.FolderAuthorize,
                                                                                                            string.Concat("Rimossa autorizzazione '", item.AuthorizationRoleType.ToString(), "' al settore '", item.Role.Name,
                                                                                                                          "' (", item.Role.EntityShortId, ") alla cartella '", entity.Name, "'"), CurrentDomainUser.Account));

                    DeleteFascicleRole(item, actualIdFascicle);
                    _unitOfWork.Repository <DossierFolderRole>().Delete(item);
                }
                DossierFolderRole newDossierFolderRole = null;
                foreach (DossierFolderRole item in entity.DossierFolderRoles.Where(f => !entityTransformed.DossierFolderRoles.Any(c => c.UniqueId == f.UniqueId)))
                {
                    newDossierFolderRole = CreateDossierFolderRole(item, entityTransformed, _unitOfWork.Repository <Role>().Find(item.Role.EntityShortId));
                    if (newDossierFolderRole != null)
                    {
                        _unitOfWork.Repository <DossierFolderRole>().Insert(newDossierFolderRole);
                    }
                }
                Role role;
                foreach (DossierFolderRole item in entity.DossierFolderRoles.Where(f => entityTransformed.DossierFolderRoles.Any(c => c.UniqueId == f.UniqueId)))
                {
                    if (entityTransformed.Fascicle != null && !_unitOfWork.Repository <FascicleRole>().ExistFascicleRolesAccounted(entityTransformed.Fascicle.UniqueId, item.Role.EntityShortId))
                    {
                        role = _unitOfWork.Repository <Role>().Find(item.Role.EntityShortId);
                        CreateFascicleRole(entityTransformed, AuthorizationRoleType.Accounted, role);
                    }
                }
            }

            _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, entityTransformed, DossierLogType.FolderModify,
                                                                                                    string.Concat("Aggiornata la cartella '", entityTransformed.Name, "'"), CurrentDomainUser.Account));

            return(base.BeforeUpdate(entity, entityTransformed));
        }