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); } }
private void CreateFascicleRole(DossierFolder dossierFolder, AuthorizationRoleType roleAuthorizationType, Role role) { FascicleRole fascicleRole = new FascicleRole() { Fascicle = dossierFolder.Fascicle, Role = role, AuthorizationRoleType = AuthorizationRoleType.Accounted }; _unitOfWork.Repository <FascicleRole>().Insert(fascicleRole); _unitOfWork.Repository <FascicleLog>().Insert(FascicleService.CreateLog(dossierFolder.Fascicle, FascicleLogType.Authorize, string.Concat("Aggiunta autorizzazione '", roleAuthorizationType.ToString(), "' al settore ", role.Name, " (", role.EntityShortId, ")"), CurrentDomainUser.Account)); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(dossierFolder.Dossier, dossierFolder, DossierLogType.FolderAuthorize, string.Concat("Aggiunta autorizzazione '", roleAuthorizationType.ToString(), "' al settore '", role.Name, "' (", role.EntityShortId, ") nel fascicolo '", dossierFolder.Fascicle.Title, "-", dossierFolder.Fascicle.FascicleObject, "'"), CurrentDomainUser.Account)); }
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)); }
protected override Fascicle BeforeCreate(Fascicle entity) { entity.FascicleFolders.Clear(); if (entity.Contacts != null) { HashSet <Contact> contacts = new HashSet <Contact>(); Contact contact = null; foreach (Contact item in entity.Contacts) { contact = _unitOfWork.Repository <Contact>().Find(item.EntityId); if (contact != null) { contacts.Add(contact); } } entity.Contacts = contacts; } if (entity.FascicleDocuments != null && entity.FascicleDocuments.Count > 0) { _unitOfWork.Repository <FascicleDocument>().InsertRange(entity.FascicleDocuments); } if (entity.Category != null) { entity.Category = _unitOfWork.Repository <Category>().Find(entity.Category.EntityShortId); } if (entity.MetadataRepository != null) { entity.MetadataRepository = _unitOfWork.Repository <MetadataRepository>().Find(entity.MetadataRepository.UniqueId); } if (entity.Container != null) { entity.Container = _unitOfWork.Repository <Container>().Find(entity.Container.EntityShortId); } if (entity.FascicleTemplate != null) { entity.FascicleTemplate = _unitOfWork.Repository <ProcessFascicleTemplate>().Find(entity.FascicleTemplate.UniqueId); } entity.Number = -1; DateTimeOffset date = entity.StartDate; entity.StartDate = DateTimeOffset.UtcNow; if (CurrentInsertActionType.HasValue && CurrentInsertActionType.Value == InsertActionType.InsertPeriodicFascicle) { CategoryFascicle relatedCategoryFascicle = _unitOfWork.Repository <CategoryFascicle>().GetByEnvironment(entity.Category.EntityShortId, entity.DSWEnvironment.Value).FirstOrDefault(); FasciclePeriod period = _unitOfWork.Repository <FasciclePeriod>().Find(relatedCategoryFascicle.FasciclePeriod.UniqueId); entity.StartDate = PeriodHelper.GetCurrentPeriodStart(period.PeriodName, date); if (entity.FascicleObject.Contains(string.Concat(" - ", period.PeriodName))) { entity.FascicleObject = entity.FascicleObject.Replace(entity.FascicleObject.Split('-').LastOrDefault(), ""); } entity.FascicleObject = string.Concat(entity.FascicleObject, " - ", period.PeriodName, ", ", period.PeriodName.Equals("Annuale", StringComparison.InvariantCultureIgnoreCase) ? entity.StartDate.Year.ToString() : CultureInfo.CurrentCulture.TextInfo.ToTitleCase(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(entity.StartDate.Month))); } entity.Year = Convert.ToInt16(entity.StartDate.Year); if (entity.Category != null) { int latestNumber = _unitOfWork.Repository <Fascicle>().GetLatestNumber(entity.Year, entity.Category.EntityShortId); entity.Number = ++latestNumber; IEnumerable <short> idCategories = entity.Category.FullIncrementalPath .Split('|') .Select(f => short.Parse(f)); string categorySectionTitle = string.Join(".", _unitOfWork.Repository <Category>().Queryable(true) .Where(f => idCategories.Contains(f.EntityShortId)) .OrderBy(f => f.EntityShortId) .Where(f => f.Code > 0) .Select(f => f.Code)); entity.Title = $"{entity.Year}.{categorySectionTitle}-{entity.Number:0000000}"; } if (entity.DossierFolders != null) { HashSet <DossierFolder> dossierFolders = new HashSet <DossierFolder>(); DossierFolder dossierFolderParent = null; DossierFolder dossierFascicleFolder = null; foreach (DossierFolder dossierFolder in entity.DossierFolders) { dossierFolderParent = _unitOfWork.Repository <DossierFolder>().GetIncludeDossier(dossierFolder.UniqueId); if (dossierFolderParent != null) { dossierFolderParent.Status = DossierFolderStatus.Folder; _unitOfWork.Repository <DossierFolder>().Update(dossierFolderParent); dossierFascicleFolder = new DossierFolder() { UniqueId = Guid.NewGuid(), Fascicle = entity, Dossier = dossierFolderParent.Dossier, ParentInsertId = dossierFolderParent.UniqueId, Name = $"{entity.Title}-{entity.FascicleObject}", Status = DossierFolderStatus.Fascicle, Category = entity.Category }; dossierFolders.Add(dossierFascicleFolder); } } entity.DossierFolders = dossierFolders; _unitOfWork.Repository <DossierFolder>().InsertRange(entity.DossierFolders); } if (entity.FascicleRoles != null) { HashSet <FascicleRole> fascicleRoles = new HashSet <FascicleRole>(); FascicleRole fascicleRole; Role role; foreach (FascicleRole item in entity.FascicleRoles) { fascicleRole = new FascicleRole(); role = _unitOfWork.Repository <Role>().Find(item.Role.EntityShortId); if (role != null && !fascicleRoles.Any(f => f.Role.EntityShortId == role.EntityShortId)) { fascicleRole.Role = role; fascicleRole.Fascicle = entity; fascicleRole.IsMaster = item.IsMaster; fascicleRole.AuthorizationRoleType = item.AuthorizationRoleType; switch (entity.FascicleType) { case FascicleType.Activity: { fascicleRole.AuthorizationRoleType = AuthorizationRoleType.Responsible; break; } case FascicleType.Procedure: case FascicleType.Period: { if (item.IsMaster) { fascicleRole.AuthorizationRoleType = AuthorizationRoleType.Responsible; } break; } } fascicleRoles.Add(fascicleRole); } } entity.FascicleRoles = fascicleRoles; _unitOfWork.Repository <FascicleRole>().InsertRange(entity.FascicleRoles); } if (!string.IsNullOrEmpty(entity.MetadataValues)) { ICollection <MetadataValueModel> metadataValueModels = JsonConvert.DeserializeObject <ICollection <MetadataValueModel> >(entity.MetadataValues); MetadataDesignerModel metadataDesignerModel = JsonConvert.DeserializeObject <MetadataDesignerModel>(entity.MetadataDesigner); ICollection <MetadataValue> metadataValues = new List <MetadataValue>(); ICollection <MetadataValueContact> metadataContactValues = new List <MetadataValueContact>(); foreach (MetadataValueModel metadataValueModel in metadataValueModels.Where(x => metadataDesignerModel.ContactFields.Any(xx => xx.KeyName == x.KeyName))) { metadataContactValues.Add(CreateMetadataContactValue(metadataValueModel, entity)); } MetadataValue metadataValue; foreach (MetadataValueModel metadataValueModel in metadataValueModels.Where(x => !metadataDesignerModel.ContactFields.Any(xx => xx.KeyName == x.KeyName))) { metadataValue = MetadataValueService.CreateMetadataValue(metadataDesignerModel, metadataValueModel); metadataValue.Fascicle = entity; metadataValues.Add(metadataValue); } entity.SourceMetadataValues = metadataValues; entity.MetadataValueContacts = metadataContactValues; _unitOfWork.Repository <MetadataValue>().InsertRange(entity.SourceMetadataValues); _unitOfWork.Repository <MetadataValueContact>().InsertRange(entity.MetadataValueContacts); } _unitOfWork.Repository <FascicleLog>().Insert(CreateLog(entity, FascicleLogType.Insert, "Inserimento nuovo fascicolo", CurrentDomainUser.Account)); _unitOfWork.Repository <FascicleFolder>().Insert(new FascicleFolder { UniqueId = entity.UniqueId, Fascicle = entity, Name = "Tutti i documenti", Category = null, Status = FascicleFolderStatus.Active, Typology = FascicleFolderTypology.Root }); return(base.BeforeCreate(entity)); }