Esempio n. 1
0
    public static IList <JsonParameter> GetCollaborationTemplateJsonParameters()
    {
        if (string.IsNullOrEmpty(_templateName))
        {
            return(null);
        }
        if (CollaborationTemplateJsonParameters != null && CollaborationTemplateJsonParameters.ContainsKey(_templateName))
        {
            return(CollaborationTemplateJsonParameters[_templateName]);
        }
        else
        {
            ICollection <WebAPIDto <TemplateCollaboration> > results = WebAPIImpersonatorFacade.ImpersonateFinder(new TemplateCollaborationFinder(DocSuiteContext.Current.Tenants),
                                                                                                                  (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.EnablePaging = false;
                finder.Name         = _templateName;
                return(finder.DoSearch());
            });

            if (results != null && results.Count > 0 && !string.IsNullOrEmpty(results.First().Entity.JsonParameters))
            {
                IList <JsonParameter> parameters = JsonConvert.DeserializeObject <IList <JsonParameter> >(results.First().Entity.JsonParameters);
                CollaborationTemplateJsonParameters.Add(_templateName, parameters);
                return(parameters);
            }
        }
        return(null);
    }
Esempio n. 2
0
        private Notification GetCollaborationToVision()
        {
            try
            {
                Notification model = new Notification();
                WebAPIFinder.Collaborations.CollaborationFinder _collaborationFinder = InitCollaborationFinder();

                WebAPIImpersonatorFacade.ImpersonateFinder(_collaborationFinder,
                                                           (impersonationType, finder) =>
                {
                    finder.UserName = DocSuiteContext.Current.User.UserName;
                    finder.Domain   = DocSuiteContext.Current.User.Domain;
                    finder.CollaborationFinderActionType = WebAPIFinder.Collaborations.CollaborationFinderActionType.ToVisionSign;
                    finder.CollaborationFinderFilterType = WebAPIFinder.Collaborations.CollaborationFinderFilterType.AllCollaborations;

                    model.NotificationName = NotificationType.CollaborazioniDaVisionare.ToString();
                    finder.DoSearchHeader();
                    model.NotificationCount = finder.Count();
                });
                return(model);
            }
            catch (Exception ex)
            {
                FileLogger.Error(LogName.WebAPIClientLog, ex.Message, ex);
                throw;
            }
        }
Esempio n. 3
0
        private void FillCollaborations(UDSEntityDto entityDto, UDSModel model)
        {
            ICollection <WebAPIDto <UDSCollaboration> > result = WebAPIImpersonatorFacade.ImpersonateFinder(UDSCollaborationFinder,
                                                                                                            (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.IdUDS          = entityDto.Id;
                finder.EnablePaging   = false;
                finder.ExpandRelation = true;
                return(finder.DoSearch());
            });

            if (result == null || !result.Select(s => s.Entity).Any())
            {
                return;
            }

            ICollection <UDSCollaboration> collaborations  = result.Select(s => s.Entity).ToList();
            IEnumerable <ReferenceModel>   referenceModels = collaborations.Select(s => new ReferenceModel()
            {
                EntityId = s.Relation.EntityId, UniqueId = s.Relation.UniqueId
            });

            model.FillCollaborations(referenceModels);
            entityDto.Collaborations = result.Select(s => s.Entity).Select(s => new UDSEntityCollaborationDto()
            {
                IdCollaboration = s.Relation.EntityId, UniqueId = s.UniqueId
            }).ToArray();
        }
Esempio n. 4
0
        private void FillProtocols(UDSEntityDto entityDto, UDSModel model)
        {
            ICollection <WebAPIDto <UDSDocumentUnit> > result = WebAPIImpersonatorFacade.ImpersonateFinder(UDSDocumentUnitFinder,
                                                                                                           (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.IdUDS             = entityDto.Id;
                finder.EnablePaging      = false;
                finder.ExpandRelation    = true;
                finder.DocumentUnitTypes = new List <Entity.UDS.UDSRelationType>()
                {
                    Entity.UDS.UDSRelationType.Protocol, Entity.UDS.UDSRelationType.ArchiveProtocol, Entity.UDS.UDSRelationType.ProtocolArchived
                };
                return(finder.DoSearch());
            });

            if (result == null || !result.Select(s => s.Entity).Any())
            {
                return;
            }

            ICollection <UDSDocumentUnit> documentUnits   = result.Select(s => s.Entity).ToList();
            IEnumerable <ReferenceModel>  referenceModels = documentUnits.Select(s => new ReferenceModel()
            {
                UniqueId = s.Relation.UniqueId
            });

            model.FillProtocols(referenceModels);
            entityDto.DocumentUnits = entityDto.DocumentUnits.Concat(documentUnits.Select(s => new UDSEntityDocumentUnitDto()
            {
                UniqueId = s.Relation.UniqueId, UDSDocumentUnitId = s.UniqueId, RelationType = Model.Entities.UDS.UDSRelationType.Protocol
            })).ToList();
        }
Esempio n. 5
0
        public ICollection <PrivacyLevel> GetCurrentPrivacyLevels()
        {
            ICollection <WebAPIDto <PrivacyLevel> > results = WebAPIImpersonatorFacade.ImpersonateFinder(_finder,
                                                                                                         (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.EnablePaging = false;
                return(finder.DoSearch());
            });

            return(results?.Select(f => f.Entity).ToList());
        }
Esempio n. 6
0
        public PrivacyLevel GetByLevel(int level)
        {
            ICollection <WebAPIDto <PrivacyLevel> > results = WebAPIImpersonatorFacade.ImpersonateFinder(_finder,
                                                                                                         (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.Level        = level;
                finder.EnablePaging = false;
                return(finder.DoSearch());
            });

            return(results?.Select(f => f.Entity).FirstOrDefault());
        }
Esempio n. 7
0
        public ICollection <PrivacyLevel> GetAllowedPrivacyLevels(int?minValue, int?maxValue)
        {
            ICollection <WebAPIDto <PrivacyLevel> > results = WebAPIImpersonatorFacade.ImpersonateFinder(_finder,
                                                                                                         (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.EnablePaging = false;
                finder.MaximumLevel = maxValue;
                finder.MinimumLevel = minValue;
                return(finder.DoSearch());
            });

            return(results?.Select(f => f.Entity).ToList());
        }
Esempio n. 8
0
        private void ConfirmRepository(UDSModel model, DateTimeOffset activeDate, Guid idRepository)
        {
            if (idRepository.Equals(Guid.Empty))
            {
                throw new ArgumentNullException("idRepository");
            }

            UDSSchemaRepositoryModelMapper repositoryschemaModelMapper = new UDSSchemaRepositoryModelMapper();
            UDSRepositoryModelMapper       repositoryModelMapper       = new UDSRepositoryModelMapper(repositoryschemaModelMapper);
            UDSBuildModel   commandModel = new UDSBuildModel(model.SerializeToXml());
            IdentityContext identity     = new IdentityContext(DocSuiteContext.Current.User.FullUserName);
            string          tenantName   = DocSuiteContext.Current.ProtocolEnv.CorporateAcronym;
            Guid            tenantId     = DocSuiteContext.Current.CurrentTenant.TenantId;

            WebAPIDto <UDSRepository> resultDto = null;

            WebAPIImpersonatorFacade.ImpersonateFinder(Currentfinder, (impersonationType, finder) =>
            {
                finder.UniqueId         = idRepository;
                finder.EnablePaging     = false;
                finder.ExpandProperties = true;
                finder.ActionType       = UDSRepositoryFinderActionType.FindElement;
                resultDto = finder.DoSearch().FirstOrDefault();
                finder.ResetDecoration();
            });

            UDSRepository repository = resultDto.Entity;

            commandModel.UDSRepository    = repositoryModelMapper.Map(repository, new UDSRepositoryModel());
            commandModel.ActiveDate       = activeDate;
            commandModel.UniqueId         = repository.UniqueId;
            commandModel.RegistrationUser = repository.RegistrationUser;

            if (repository.Version > 0)
            {
                ICommandUpdateUDS commandUpdate = new CommandUpdateUDS(CurrentTenant.TenantName, CurrentTenant.UniqueId, CurrentTenant.TenantAOO.UniqueId, identity, commandModel);
                CommandFacade <ICommandUpdateUDS> commandUpdateFacade = new CommandFacade <ICommandUpdateUDS>();
                commandUpdateFacade.Push(commandUpdate);
            }
            else
            {
                ICommandCreateUDS commandInsert = new CommandCreateUDS(CurrentTenant.TenantName, CurrentTenant.UniqueId, CurrentTenant.TenantAOO.UniqueId, identity, commandModel);
                CommandFacade <ICommandCreateUDS> commandCreateFacade = new CommandFacade <ICommandCreateUDS>();
                commandCreateFacade.Push(commandInsert);
            }
        }
Esempio n. 9
0
        private ValidatorResult ValidateEditRuleset(ValidatorResult resultModel)
        {
            resultModel = ValidateBase(resultModel);
            Category dbCategory = FacadeFactory.Instance.CategoryFacade.GetById(this._categoryToValidate.Id);

            if (dbCategory.StartDate != this._categoryToValidate.StartDate)
            {
                ICollection <WebAPIDto <DocumentUnitModel> > result = WebAPIImpersonatorFacade.ImpersonateFinder(new DocumentUnitModelFinder(DocSuiteContext.Current.Tenants),
                                                                                                                 (impersonationType, finder) =>
                {
                    finder.DocumentUnitFinderAction = DocumentUnitFinderActionType.CategorizedUD;
                    finder.CategoryId = this._categoryToValidate.UniqueId;
                    return(finder.DoSearch());
                });

                if (FacadeFactory.Instance.CategoryFacade.IsUsed(ref dbCategory) || result.Count > 0)
                {
                    resultModel.Errors.Add(CATEGORY_USED_ERROR_MESSAGE);
                }
            }

            if (this._categoryToValidate.CategorySchema != null)
            {
                if (dbCategory.CategorySchema.Id != this._categoryToValidate.CategorySchema.Id)
                {
                    resultModel.Errors.Add(ANOTHER_SCHEMA_ERROR_MESSAGE);
                }
            }

            if (dbCategory.HasChildren)
            {
                if (dbCategory.Children.Any(x => x.StartDate < this._categoryToValidate.StartDate))
                {
                    resultModel.Errors.Add(START_DATE_CHILD_ERROR_MESSAGE);
                }
            }

            return(resultModel);
        }
Esempio n. 10
0
        private void FillAuthorization(UDSEntityDto entityDto, UDSModel model)
        {
            ICollection <UDSRole> roles = new List <UDSRole>();

            ICollection <WebAPIDto <UDSRole> > result = WebAPIImpersonatorFacade.ImpersonateFinder(UDSRoleFinder,
                                                                                                   (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.IdUDS          = entityDto.Id;
                finder.EnablePaging   = false;
                finder.ExpandRelation = true;
                return(finder.DoSearch());
            });

            if (result == null)
            {
                return;
            }

            roles = result.Select(f => f.Entity).ToList();

            if (roles == null || roles.Count() < 1)
            {
                return;
            }

            IEnumerable <ReferenceModel> referenceModels = roles.Select(s => new ReferenceModel()
            {
                EntityId = s.Relation.EntityShortId, UniqueId = s.UniqueId, AuthorizationType = (AuthorizationType)s.AuthorizationType
            });

            model.FillAuthorizations(referenceModels, model.Model.Authorizations.Label);
            entityDto.Authorizations = roles.Select(s => new UDSEntityRoleDto()
            {
                IdRole = s.Relation.EntityShortId, UniqueId = s.UniqueId, AuthorizationType = (AuthorizationType)s.AuthorizationType
            }).ToArray();
        }
Esempio n. 11
0
 public ICollection <Tenant> GetAuthorizedTenants()
 {
     return(WebAPIImpersonatorFacade.ImpersonateFinder(new UserTenantFinder(DocSuiteContext.Current.Tenants),
                                                       (impersonationType, finder) =>
     {
         try
         {
             finder.EnablePaging = false;
             ICollection <WebAPIDto <Tenant> > results = finder.DoSearch();
             ICollection <Tenant> tenants;
             if (results != null)
             {
                 tenants = results.Select(r => r.Entity).ToList();
                 return tenants;
             }
         }
         catch (Exception ex)
         {
             FileLogger.Error(LogName.FileLog, string.Concat("GetAuthorizedTenants -> ", ex.Message), ex);
         }
         FileLogger.Warn(LogName.FileLog, string.Concat("GetAuthorizedTenants -> Result is null.", HttpContext.Current.User.Identity));
         return null;
     }));
 }
Esempio n. 12
0
        public Tenant GetCurrentTenant()
        {
            try
            {
                ICollection <Tenant> userTenants = WebAPIImpersonatorFacade.ImpersonateFinder(new UserTenantFinder(DocSuiteContext.Current.Tenants),
                                                                                              (impersonationType, finder) =>
                {
                    finder.EnablePaging = false;
                    ICollection <WebAPIDto <Tenant> > results = finder.DoSearch();
                    ICollection <Tenant> tenants = null;
                    if (results != null)
                    {
                        tenants = results.Select(r => r.Entity).ToList();
                    }
                    return(tenants);
                });

                UserLog currentUserLog = FacadeFactory.Instance.UserLogFacade.GetByUser(DocSuiteContext.Current.User.FullUserName);
                Tenant  currentTenant;
                ICollection <Entity.Commons.Container> tmpTenantContainers;
                int  odataSkip      = 0;
                bool readContainers = true;
                foreach (Tenant item in userTenants)
                {
                    if (item.UniqueId == currentUserLog.CurrentTenantId)
                    {
                        currentTenant = WebAPIImpersonatorFacade.ImpersonateFinder(new TenantFinder(DocSuiteContext.Current.Tenants),
                                                                                   (impersonationType, finder) =>
                        {
                            finder.IncludeContainers = false;
                            finder.IncludeTenantAOO  = true;
                            finder.UniqueId          = item.UniqueId;
                            finder.EnablePaging      = false;
                            return(finder.DoSearch().Select(s => s.Entity).FirstOrDefault());
                        });

                        do
                        {
                            tmpTenantContainers = WebAPIImpersonatorFacade.ImpersonateFinder(new Data.WebAPI.Finder.Commons.ContainerFinder(DocSuiteContext.Current.Tenants),
                                                                                             (impersonationType, finder) =>
                            {
                                finder.IdTenant     = item.UniqueId;
                                finder.EnablePaging = true;
                                finder.PageIndex    = odataSkip;
                                finder.PageSize     = DocSuiteContext.Current.DefaultODataTopQuery;
                                return(finder.DoSearch().Select(s => s.Entity).ToList());
                            });

                            currentTenant.Containers = currentTenant.Containers.Union(tmpTenantContainers).ToList();
                            odataSkip     += tmpTenantContainers.Count;
                            readContainers = tmpTenantContainers.Count >= DocSuiteContext.Current.DefaultODataTopQuery;
                        } while (readContainers);
                        return(currentTenant);
                    }
                }
            }
            catch (Exception ex)
            {
                FileLogger.Error(LogName.FileLog, string.Concat("GetCurrentTenant -> ", ex.Message), ex);
            }
            FileLogger.Warn(LogName.FileLog, string.Concat("GetCurrentTenant -> Result is null.", HttpContext.Current.User.Identity));
            return(null);
        }
Esempio n. 13
0
        /// <summary>
        /// Salva o modifica una Bozza in UDSRepositories
        /// </summary>
        /// <returns>Il medesimo IdRepository del parametro idRepository se l'oggetto si trova in stato Bozza, altrimenti viene creato un nuovo ID</returns>
        private Guid SaveDraftRepository(UDSModel model, Guid idRepository)
        {
            UDSRepository repository      = null;
            UDSRepository savedRepository = null;

            if (!idRepository.Equals(Guid.Empty))
            {
                WebAPIImpersonatorFacade.ImpersonateFinder(Currentfinder, (impersonationType, finder) =>
                {
                    //Se il repository recuperato è in stato Bozza allora procedo alla modifica del medesimo oggetto,
                    //viceversa creo sempre una nuova Bozza.
                    finder.UniqueId                     = idRepository;
                    finder.EnablePaging                 = false;
                    finder.ExpandProperties             = true;
                    finder.ActionType                   = UDSRepositoryFinderActionType.FindElement;
                    WebAPIDto <UDSRepository> resultDto = finder.DoSearch().FirstOrDefault();
                    finder.ResetDecoration();
                    if (resultDto != null && resultDto.Entity != null)
                    {
                        savedRepository = resultDto.Entity;
                        repository      = (savedRepository.Status.Equals(Entity.UDS.UDSRepositoryStatus.Draft)) ? savedRepository : null;
                    }
                });
            }

            short idContainer = -1;

            if (repository == null)
            {
                repository = new UDSRepository()
                {
                    ModuleXML = model.SerializeToXml(),
                    Name      = model.Model.Title,
                    Status    = Entity.UDS.UDSRepositoryStatus.Draft,
                    Version   = idRepository.Equals(Guid.Empty) ? (short)0 : savedRepository.Version,
                    Alias     = model.Model.Alias
                };

                repository.Container = null;
                if (repository.Version > 0)
                {
                    model.Model.Container.IdContainer = savedRepository.Container.EntityShortId.ToString();
                    model.Model.Title = savedRepository.Name;
                    model.Model.Alias = savedRepository.Alias;
                    model.Model.Container.CreateContainer = false;
                    if (model.Model.Documents != null && model.Model.Documents.Document != null)
                    {
                        model.Model.Documents.Document.CreateBiblosArchive = false;
                    }
                    if (model.Model.Documents != null && model.Model.Documents.DocumentDematerialisation != null)
                    {
                        model.Model.Documents.DocumentDematerialisation.CreateBiblosArchive = false;
                    }

                    repository.Name      = savedRepository.Name;
                    repository.Alias     = savedRepository.Alias;
                    repository.Container = savedRepository.Container;
                    repository.ModuleXML = model.SerializeToXml();
                }
                if (savedRepository == null && model.Model.Container != null && !string.IsNullOrEmpty(model.Model.Container.IdContainer) && short.TryParse(model.Model.Container.IdContainer, out idContainer))
                {
                    repository.Container = new Entity.Commons.Container()
                    {
                        EntityShortId = idContainer
                    };
                }

                Save(repository);
            }
            else
            {
                repository.Container = savedRepository == null ? null : repository.Container;
                if (repository.Version > 0)
                {
                    model.Model.Container.IdContainer = savedRepository.Container.EntityShortId.ToString();
                    model.Model.Title = savedRepository.Name;
                    model.Model.Alias = savedRepository.Alias;
                    model.Model.Container.CreateContainer = false;
                    if (model.Model.Documents != null && model.Model.Documents.Document != null)
                    {
                        model.Model.Documents.Document.CreateBiblosArchive = false;
                    }
                    if (model.Model.Documents != null && model.Model.Documents.DocumentDematerialisation != null)
                    {
                        model.Model.Documents.DocumentDematerialisation.CreateBiblosArchive = false;
                    }

                    repository.Name      = savedRepository.Name;
                    repository.Alias     = savedRepository.Alias;
                    repository.Container = savedRepository.Container;
                    repository.ModuleXML = model.SerializeToXml();
                }
                if (savedRepository == null && model.Model.Container != null && !string.IsNullOrEmpty(model.Model.Container.IdContainer) && short.TryParse(model.Model.Container.IdContainer, out idContainer))
                {
                    repository.Container = new Entity.Commons.Container()
                    {
                        EntityShortId = idContainer
                    };
                }
                repository.ModuleXML = model.SerializeToXml();
                repository.Name      = model.Model.Title;
                repository.Alias     = model.Model.Alias;

                Update(repository);
            }

            return(repository.UniqueId);
        }
        public ProtocolInitializer GetProtocolInitializer(IReadOnlyCollection <TenantModel> tenantModels, ProtocolModel protocolModel,
                                                          Collaboration collaboration, WorkflowProperty dsw_p_CollaborationSignSummaryTemplateId, WorkflowProperty dsw_a_Collaboration_GenerateSignSummary,
                                                          WorkflowProperty dsw_p_ProposerRole, UDSDto udsDto)
        {
            ProtocolInitializer protInitializer = new ProtocolInitializer();

            // Oggetto
            protInitializer.Subject = protocolModel.Object;
            // Protocol Type
            protInitializer.ProtocolType = protocolModel.ProtocolType.EntityShortId;
            //Note
            protInitializer.Notes = protocolModel.Note;
            //Protocollo
            protInitializer.DocumentProtocol = protocolModel.DocumentProtocol;
            //Date
            protInitializer.DocumentDate = protocolModel.DocumentDate;
            // Classificazione
            if (protocolModel.Category != null && protocolModel.Category.IdCategory.HasValue)
            {
                protInitializer.Category = FacadeFactory.Instance.CategoryFacade.GetById(protocolModel.Category.IdCategory.Value);
            }
            if (protocolModel.Container != null && protocolModel.Container.IdContainer.HasValue)
            {
                protInitializer.Containers = new List <Data.Container> {
                    FacadeFactory.Instance.ContainerFacade.GetById(Convert.ToInt32(protocolModel.Container.IdContainer))
                };
            }
            if (protocolModel.DocumentTypeCode != null)
            {
                protInitializer.DocumentTypeLabel = FacadeFactory.Instance.TableDocTypeFacade.GetByCode(protocolModel.DocumentTypeCode).Description;
            }

            string owner = DocSuiteContext.Current.User.UserName;

            // Gestione documenti
            if (protocolModel.MainDocument != null && !string.IsNullOrEmpty(protocolModel.MainDocument.FileName) &&
                (protocolModel.MainDocument.ContentStream != null || protocolModel.MainDocument.DocumentId.HasValue))
            {
                protInitializer.MainDocument = SaveStream(owner, protocolModel.MainDocument);
            }

            // Allegati
            IEnumerable <DocumentModel> results = null;

            if (protocolModel.Attachments != null && (results = protocolModel.Attachments.Where(f => !string.IsNullOrEmpty(f.FileName) && (f.ContentStream != null || f.DocumentId.HasValue))).Any())
            {
                protInitializer.Attachments = SaveStream(owner, results);
            }

            if (collaboration != null && dsw_p_CollaborationSignSummaryTemplateId != null && dsw_a_Collaboration_GenerateSignSummary != null &&
                dsw_a_Collaboration_GenerateSignSummary.ValueBoolean.HasValue && dsw_a_Collaboration_GenerateSignSummary.ValueBoolean.Value &&
                dsw_p_CollaborationSignSummaryTemplateId.ValueGuid.HasValue && dsw_p_CollaborationSignSummaryTemplateId.ValueGuid.Value != Guid.Empty)
            {
                TemplateDocumentRepository templateDocumentRepository = WebAPIImpersonatorFacade.ImpersonateFinder(new TemplateDocumentRepositoryFinder(tenantModels),
                                                                                                                   (impersonationType, finder) =>
                {
                    finder.UniqueId     = dsw_p_CollaborationSignSummaryTemplateId.ValueGuid.Value;
                    finder.EnablePaging = false;
                    return(finder.DoSearch().SingleOrDefault()?.Entity);
                });

                if (templateDocumentRepository != null)
                {
                    BiblosChainInfo        biblosChainInfo    = new BiblosChainInfo(templateDocumentRepository.IdArchiveChain);
                    DocumentInfo           biblosDocumentInfo = biblosChainInfo.Documents.Single(f => !f.IsRemoved);
                    List <BuildValueModel> buildValueModels   = new List <BuildValueModel>();
                    buildValueModels.Add(new BuildValueModel()
                    {
                        IsHTML = false,
                        Name   = "oggetto",
                        Value  = protInitializer.Subject,
                    });
                    DateTime signDate;
                    string   token;
                    foreach (CollaborationSign item in collaboration.CollaborationSigns)
                    {
                        signDate = item.SignDate ?? item.LastChangedDate.Value.DateTime;
                        token    = signDate.DayOfWeek == DayOfWeek.Sunday ? "la" : "il";
                        buildValueModels.Add(new BuildValueModel()
                        {
                            IsHTML = false,
                            Name   = $"signer_info_{item.Incremental}",
                            Value  = $"{item.SignName} {token} {signDate.ToLongDateString()}",
                        });
                    }
                    buildValueModels = BuildValueProposerRole(dsw_p_ProposerRole, buildValueModels);
                    buildValueModels = BuildValueUDS(udsDto, buildValueModels);
                    byte[] pdf = Services.StampaConforme.Service.BuildPDF(biblosDocumentInfo.Stream, buildValueModels.ToArray(), string.Empty);
                    if (protInitializer.Attachments == null)
                    {
                        protInitializer.Attachments = new List <DocumentInfo>();
                    }
                    protInitializer.Attachments.Add(SaveStream(owner, pdf, "riepilogo_firmatari.pdf"));
                }
            }
            // Annessi
            results = null;
            if (protocolModel.Annexes != null && (results = protocolModel.Annexes.Where(f => !string.IsNullOrEmpty(f.FileName) && (f.ContentStream != null || f.DocumentId.HasValue))).Any())
            {
                protInitializer.Annexed = SaveStream(owner, results);
            }

            // Contatti
            protInitializer.Senders    = new List <Data.ContactDTO>();
            protInitializer.Recipients = new List <Data.ContactDTO>();
            if (protocolModel.ContactManuals != null && protocolModel.ContactManuals.Any())
            {
                foreach (ProtocolContactManualModel protocolContactManualModel in protocolModel.ContactManuals)
                {
                    Data.Contact contact = new Data.Contact();
                    contact.ContactType   = new Data.ContactType(Data.ContactType.Aoo);
                    contact.Description   = protocolContactManualModel.Description;
                    contact.CertifiedMail = protocolContactManualModel.CertifiedEmail;
                    contact.EmailAddress  = protocolContactManualModel.EMail;
                    if (!string.IsNullOrEmpty(protocolContactManualModel.Address))
                    {
                        contact.Address         = new Data.Address();
                        contact.Address.Address = protocolContactManualModel.Address;
                    }

                    if (protocolContactManualModel.ComunicationType == ComunicationType.Sender)
                    {
                        protInitializer.Senders.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Manual));
                    }
                    else
                    {
                        protInitializer.Recipients.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Manual));
                    }
                }
            }
            if (protocolModel.Contacts != null && protocolModel.Contacts.Any())
            {
                foreach (ProtocolContactModel protocolContactModel in protocolModel.Contacts)
                {
                    Data.Contact contact = FacadeFactory.Instance.ContactFacade.GetById(protocolContactModel.IdContact);
                    if (protocolContactModel.ComunicationType == ComunicationType.Sender)
                    {
                        protInitializer.Senders.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Address));
                    }
                    else
                    {
                        protInitializer.Recipients.Add(new Data.ContactDTO(contact, Data.ContactDTO.ContactType.Address));
                    }
                }
            }
            return(protInitializer);
        }
Esempio n. 15
0
        private void FillContacts(UDSEntityDto entityDto, UDSModel model)
        {
            if (model.Model.Contacts.IsNullOrEmpty())
            {
                return;
            }

            ICollection <WebAPIDto <UDSContact> > result = WebAPIImpersonatorFacade.ImpersonateFinder(UDSContactFinder,
                                                                                                      (impersonationType, finder) =>
            {
                finder.ResetDecoration();
                finder.IdUDS          = entityDto.Id;
                finder.EnablePaging   = false;
                finder.ExpandRelation = true;
                return(finder.DoSearch());
            });

            if (result == null || !result.Select(s => s.Entity).Any())
            {
                return;
            }

            entityDto.Contacts = result.Select(s => s.Entity).Select(s => new UDSEntityContactDto()
            {
                ContactManual = s.ContactManual,
                ContactType   = (Helpers.UDS.UDSContactType)s.ContactType,
                IdContact     = s.Relation?.EntityId,
                UDSContactId  = s.UniqueId,
                Label         = s.ContactLabel
            }).ToList();

            foreach (Contacts modelContacts in model.Model.Contacts)
            {
                IList <UDSEntityContactDto> contacts = entityDto.Contacts.Where(x => x.Label.Eq(modelContacts.Label)).ToList();
                if (contacts == null || !contacts.Any())
                {
                    continue;
                }

                foreach (UDSEntityContactDto contact in contacts)
                {
                    if (contact.ContactType == Helpers.UDS.UDSContactType.Contact)
                    {
                        if (contact.IdContact.HasValue)
                        {
                            ContactInstance newInstance = new ContactInstance()
                            {
                                IdContact = contact.IdContact.Value
                            };
                            modelContacts.ContactInstances = (modelContacts.ContactInstances ?? Enumerable.Empty <ContactInstance>()).Concat(new ContactInstance[] { newInstance }).ToArray();
                        }
                    }
                    else
                    {
                        ContactManualInstance newManualInstance = new ContactManualInstance()
                        {
                            ContactDescription = contact.ContactManual
                        };
                        modelContacts.ContactManualInstances = (modelContacts.ContactManualInstances ?? Enumerable.Empty <ContactManualInstance>()).Concat(new ContactManualInstance[] { newManualInstance }).ToArray();
                    }
                }
            }
        }