protected override DossierRole BeforeDelete(DossierRole entity, DossierRole entityTransformed) { _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity.Dossier, null, DossierLogType.Authorize, string.Concat("Rimossa autorizzazione '", entity.AuthorizationRoleType.ToString(), "' al settore ", entity.Role.Name, " (", entity.Role.EntityShortId, ")"), CurrentDomainUser.Account)); return(base.BeforeDelete(entity, entityTransformed)); }
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); }
private DossierRole CreateDossierRole(DossierRole entity, Dossier dossier) { DossierRole dossierRole = null; if (entity.Role == null) { return(dossierRole); } Role role = _unitOfWork.Repository <Role>().Find(entity.Role.EntityShortId); if (role != null) { dossierRole = new DossierRole { Role = role, Dossier = dossier, AuthorizationRoleType = entity.AuthorizationRoleType, IsMaster = entity.IsMaster, Status = DossierRoleStatus.Active }; _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(dossier, null, DossierLogType.Authorize, string.Concat("Autorizzato il dossier al settore '", role.Name, "' (", role.EntityShortId, ") responsabile (Responsible)"), CurrentDomainUser.Account)); } return(dossierRole); }
protected override DossierDocument BeforeCreate(DossierDocument entity) { if (entity.Dossier != null) { entity.Dossier = _unitOfWork.Repository <Dossier>().Find(entity.Dossier.UniqueId); } _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity.Dossier, null, DossierLogType.Modify, "Modifica del Dossier", CurrentDomainUser.Account)); return(base.BeforeCreate(entity)); }
protected override DossierRole BeforeCreate(DossierRole entity) { if (entity.Dossier != null) { entity.Dossier = _unitOfWork.Repository <Dossier>().Find(entity.Dossier.UniqueId); } if (entity.Role != null) { entity.Role = _unitOfWork.Repository <Role>().Find(entity.Role.EntityShortId); } _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity.Dossier, null, DossierLogType.Authorize, string.Concat("Aggiunta autorizzazione '", entity.AuthorizationRoleType.ToString(), "' al settore ", entity.Role.Name, " (", entity.Role.EntityShortId, ")"), CurrentDomainUser.Account)); return(base.BeforeCreate(entity)); }
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)); }
private void CreateOrUpdateFolderHystoryLog(DossierFolder entityTransformed) { DossierLog logDossier = _unitOfWork.Repository <DossierLog>().GetFolderHystoryLog(entityTransformed.UniqueId).SingleOrDefault(); DossierFolder toStore = new DossierFolder() { Name = entityTransformed.Name }; string serializedEntity = JsonConvert.SerializeObject(toStore, DefaultJsonSerializer); if (logDossier == null) { _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, entityTransformed, DossierLogType.FolderHystory, serializedEntity, CurrentDomainUser.Account)); return; } logDossier.LogDescription = serializedEntity; _unitOfWork.Repository <DossierLog>().Update(logDossier); }
protected override DossierFolder BeforeDelete(DossierFolder entity, DossierFolder entityTransformed) { if (entity.ParentInsertId.HasValue && entityTransformed.DossierFolderLevel > 2) { int countChildren = _unitOfWork.Repository <DossierFolder>().CountChildren(entity.ParentInsertId.Value); if (countChildren == 1) { DossierFolder parentFolder = _unitOfWork.Repository <DossierFolder>().Find(entity.ParentInsertId); parentFolder.Status = DossierFolderStatus.InProgress; _unitOfWork.Repository <DossierFolder>().Update(parentFolder); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, parentFolder, DossierLogType.FolderModify, string.Concat("Aggiornata la tipologia della cartella '", parentFolder.Name, "' da 'Cartella con sotto cartelle' a 'Cartella'"), CurrentDomainUser.Account)); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, parentFolder, DossierLogType.FolderModify, string.Concat("Aggiornata la cartella '", parentFolder.Name, "'"), CurrentDomainUser.Account)); } } if (entityTransformed.DossierFolderRoles != null && entityTransformed.DossierFolderRoles.Any()) { _unitOfWork.Repository <DossierFolderRole>().DeleteRange(entityTransformed.DossierFolderRoles.ToList()); } if (entityTransformed.DossierLogs != null && entityTransformed.DossierLogs.Any()) { foreach (DossierLog item in entityTransformed.DossierLogs) { item.DossierFolder = null; } } _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed.Dossier, null, DossierLogType.FolderDelete, string.Concat("Eliminata la cartella '", entityTransformed.Name, "'"), CurrentDomainUser.Account)); return(base.BeforeDelete(entity, entityTransformed)); }
protected override DossierFolder BeforeCreate(DossierFolder entity) { if (CurrentInsertActionType.HasValue && CurrentInsertActionType == Common.Infrastructures.InsertActionType.CloneProcessDetails) { //TODO: The UniqueId of the clicked folder which will server as the source folder is stored in JsonMetadata (should I move it?) DossierFolder sourceDossierFolder = ExtractSourceToClone(Guid.Parse(entity.JsonMetadata)); entity = CloneDossierFolder(sourceDossierFolder, entity); entity.JsonMetadata = "parent"; entity.Name = $"1-{entity.Name}"; //establish reorder in SQL after Entity Framework insert. _unitOfWork.Repository <DossierFolder>().Insert(entity); /*Load children inside sourceDossier Folder*/ List <DossierFolder> dossierChildren = _unitOfWork.Repository <DossierFolder>() .Query(x => x.DossierFolderPath.StartsWith(sourceDossierFolder.DossierFolderPath) && x.DossierFolderLevel > sourceDossierFolder.DossierFolderLevel && x.Status != DossierFolderStatus.Fascicle, true) .SelectAsQueryable().ToList(); AddClonedChildren(entity, dossierChildren); return(base.BeforeCreate(entity)); } if (entity.Dossier != null) { entity.Dossier = _unitOfWork.Repository <Dossier>().GetWithProcesses(entity.Dossier.UniqueId).SingleOrDefault(); } if (entity.Category != null) { entity.Category = _unitOfWork.Repository <Category>().Find(entity.Category.EntityShortId); } entity.Status = entity.Status == DossierFolderStatus.DoAction ? DossierFolderStatus.DoAction : DossierFolderStatus.InProgress; if (entity.Fascicle != null) { entity.Fascicle = _unitOfWork.Repository <Fascicle>().Find(entity.Fascicle.UniqueId); entity.Status = DossierFolderStatus.Fascicle; CreateOrUpdateFolderHystoryLog(entity); entity.Name = string.Concat(entity.Fascicle.Title, "-", entity.Fascicle.FascicleObject); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity.Dossier, entity, DossierLogType.FolderModify, string.Concat("Aggiornata la cartella '", entity.Name, "' con fascicolo associato '", entity.Fascicle.Title, "-", entity.Fascicle.FascicleObject, "'"), CurrentDomainUser.Account)); } _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity.Dossier, entity, DossierLogType.FolderInsert, string.Concat("Creata cartella '", entity.Name, "' ", entity.Fascicle != null ? string.Concat(" con fascicolo associato '", entity.Fascicle.Title, "-", entity.Fascicle.FascicleObject, "'") : string.Empty), CurrentDomainUser.Account)); if (entity.DossierFolderRoles != null) { HashSet <DossierFolderRole> dossierFolderRoles = new HashSet <DossierFolderRole>(); foreach (DossierFolderRole item in entity.DossierFolderRoles) { dossierFolderRoles.Add(CreateDossierFolderRole(item, entity, _unitOfWork.Repository <Role>().Find(item.Role.EntityShortId))); } entity.DossierFolderRoles = dossierFolderRoles.Where(f => f != null).ToList(); _unitOfWork.Repository <DossierFolderRole>().InsertRange(entity.DossierFolderRoles); } if (entity.ParentInsertId.HasValue) { DossierFolder parentFolder = _unitOfWork.Repository <DossierFolder>().Find(entity.ParentInsertId); if (parentFolder != null && parentFolder.DossierFolderLevel > 1) { parentFolder.Status = DossierFolderStatus.Folder; _unitOfWork.Repository <DossierFolder>().Update(parentFolder); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity.Dossier, parentFolder, DossierLogType.FolderModify, string.Concat("Aggiornata la tipologia della cartella '", parentFolder.Name, "' da 'Cartella' a 'Cartella con sotto cartelle'"), CurrentDomainUser.Account)); } } if (entity.Dossier != null) { foreach (Process item in entity.Dossier.Processes.Where(f => f.ProcessType == ProcessType.Created)) { item.ProcessType = ProcessType.Defined; _unitOfWork.Repository <Process>().Update(item); } } return(base.BeforeCreate(entity)); }
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)); }
protected override Dossier BeforeCreate(Dossier entity) { _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity, null, DossierLogType.Insert, string.Concat("Nuovo dossier '", entity.Subject, "'"), CurrentDomainUser.Account)); 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.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.DossierRoles != null) { HashSet <DossierRole> dossierRoles = new HashSet <DossierRole>(); foreach (DossierRole item in entity.DossierRoles) { dossierRoles.Add(CreateDossierRole(item, entity)); } entity.DossierRoles = dossierRoles.Where(f => f != null).ToList(); _unitOfWork.Repository <DossierRole>().InsertRange(entity.DossierRoles); } if (entity.DossierDocuments != null && entity.DossierDocuments.Count > 0) { _unitOfWork.Repository <DossierDocument>().InsertRange(entity.DossierDocuments); } 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.Dossier = entity; metadataValues.Add(metadataValue); } entity.SourceMetadataValues = metadataValues; entity.MetadataValueContacts = metadataContactValues; _unitOfWork.Repository <MetadataValue>().InsertRange(entity.SourceMetadataValues); _unitOfWork.Repository <MetadataValueContact>().InsertRange(entity.MetadataValueContacts); } if (entity.Category != null) { entity.Category = _unitOfWork.Repository <Category>().Find(entity.Category.EntityShortId); } else { UserLog userLog = _unitOfWork.Repository <UserLog>().GetBySystemUser(CurrentDomainUser.Account); Tenant currentTenant = _unitOfWork.Repository <Tenant>().GetByUniqueId(userLog.CurrentTenantId).FirstOrDefault(); entity.Category = _unitOfWork.Repository <Category>().GetDefaultCategoryByTenantAOOId(currentTenant.TenantAOO.UniqueId); } entity.Status = DossierStatus.Open; entity.Year = Convert.ToInt16(DateTime.UtcNow.Year); entity.Number = -1; int latestNumber = _unitOfWork.Repository <Dossier>().GetLatestNumber(entity.Year); entity.Number = ++latestNumber; DossierFolder rootNode = new DossierFolder { UniqueId = entity.UniqueId, Dossier = entity, Name = $"Dossier {entity.Year}/{entity.Number:0000000}" , Status = DossierFolderStatus.InProgress, }; _unitOfWork.Repository <DossierFolder>().Insert(rootNode); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entity, rootNode, DossierLogType.FolderInsert, string.Concat("Creata cartella radice '", rootNode.Name, "'"), CurrentDomainUser.Account)); return(base.BeforeCreate(entity)); }
protected override Dossier BeforeUpdate(Dossier entity, Dossier entityTransformed) { if (entity.Contacts != null) { foreach (Contact item in entityTransformed.Contacts.Where(f => !entity.Contacts.Any(c => c.EntityId == f.EntityId)).ToList()) { entityTransformed.Contacts.Remove(item); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.Modify, string.Concat("Rimosso il contatto '", item.Description, "'"), CurrentDomainUser.Account)); } foreach (Contact item in entity.Contacts.Where(f => !entityTransformed.Contacts.Any(c => c.EntityId == f.EntityId))) { entityTransformed.Contacts.Add(_unitOfWork.Repository <Contact>().Find(item.EntityId)); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.Modify, string.Concat("Aggiunto il contatto '", item.Description, "'"), CurrentDomainUser.Account)); } } if (entity.DossierDocuments != null && entity.DossierDocuments.Any()) { foreach (DossierDocument item in entity.DossierDocuments.Where(x => !entityTransformed.DossierDocuments.Any(f => f.UniqueId == x.UniqueId))) { _unitOfWork.Repository <DossierDocument>().Insert(item); entityTransformed.DossierDocuments.Add(item); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.DocumentInsert, string.Concat("Inserimento documento con id catena ", item.IdArchiveChain), CurrentDomainUser.Account)); } } if (entity.Container != null) { entityTransformed.Container = _unitOfWork.Repository <Container>().Find(entity.Container.EntityShortId); } if (entityTransformed.SourceMetadataValues != null && entityTransformed.MetadataValueContacts != null && !string.IsNullOrEmpty(entity.MetadataValues)) { ICollection <MetadataValueModel> metadataValueModels = JsonConvert.DeserializeObject <ICollection <MetadataValueModel> >(entity.MetadataValues); MetadataDesignerModel metadataDesignerModel = JsonConvert.DeserializeObject <MetadataDesignerModel>(entityTransformed.MetadataDesigner); foreach (MetadataValue item in entityTransformed.SourceMetadataValues.Where(c => !metadataValueModels.Any(x => x.KeyName == c.Name)).ToList()) { _unitOfWork.Repository <MetadataValue>().Delete(item); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.Modify, string.Concat("Rimosso il metadato '", item.Name, "'"), CurrentDomainUser.Account)); } foreach (MetadataValueContact item in entityTransformed.MetadataValueContacts.Where(c => !metadataValueModels.Any(x => x.KeyName == c.Name)).ToList()) { _unitOfWork.Repository <MetadataValueContact>().Delete(item); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.Modify, string.Concat("Rimosso il metadato '", item.Name, "'"), CurrentDomainUser.Account)); } MetadataValueContact tmpContactValue; foreach (MetadataValueContact item in entityTransformed.MetadataValueContacts.Where(c => metadataValueModels.Any(x => x.KeyName == c.Name)).ToList()) { tmpContactValue = CreateMetadataContactValue(metadataValueModels.Single(x => x.KeyName == item.Name), entityTransformed); item.Contact = tmpContactValue.Contact; item.ContactManual = tmpContactValue.ContactManual; _unitOfWork.Repository <MetadataValueContact>().Update(item); } MetadataValue tmpMetadataValue; foreach (MetadataValue item in entityTransformed.SourceMetadataValues.Where(c => metadataValueModels.Any(x => x.KeyName == c.Name)).ToList()) { tmpMetadataValue = MetadataValueService.CreateMetadataValue(metadataDesignerModel, metadataValueModels.Single(x => x.KeyName == item.Name)); _mapperUnitOfWork.Repository <IDomainMapper <MetadataValue, MetadataValue> >().Map(tmpMetadataValue, item); _unitOfWork.Repository <MetadataValue>().Update(item); } foreach (MetadataValueModel metadataValueModel in metadataValueModels.Where(x => metadataDesignerModel.ContactFields.Any(xx => xx.KeyName == x.KeyName) && !entityTransformed.MetadataValueContacts.Any(xx => xx.Name == x.KeyName))) { _unitOfWork.Repository <MetadataValueContact>().Insert(CreateMetadataContactValue(metadataValueModel, entityTransformed)); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.Modify, string.Concat("Creato il metadato '", metadataValueModel.KeyName, "'"), CurrentDomainUser.Account)); } foreach (MetadataValueModel metadataValueModel in metadataValueModels.Where(x => !metadataDesignerModel.ContactFields.Any(xx => xx.KeyName == x.KeyName) && !entityTransformed.SourceMetadataValues.Any(xx => xx.Name == x.KeyName))) { tmpMetadataValue = MetadataValueService.CreateMetadataValue(metadataDesignerModel, metadataValueModel); tmpMetadataValue.Dossier = entityTransformed; _unitOfWork.Repository <MetadataValue>().Insert(tmpMetadataValue); _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, DossierLogType.Modify, string.Concat("Creato il metadato '", metadataValueModel.KeyName, "'"), CurrentDomainUser.Account)); } } _unitOfWork.Repository <DossierLog>().Insert(BaseDossierService <DossierLog> .CreateLog(entityTransformed, null, entity.EndDate.HasValue ? DossierLogType.Close : DossierLogType.Modify, string.Concat(entity.EndDate.HasValue ? "Chiusura" : "Modifica", " del Dossier"), CurrentDomainUser.Account)); return(base.BeforeUpdate(entity, entityTransformed)); }