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); }
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; } }
public bool HasViewableRight(Guid idDocumentUnit, string username, string domain) { string odataFilter = $"/DocumentUnitService.HasViewableDocument(idDocumentUnit={idDocumentUnit},username='******',domain='{domain}')"; IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME)); TenantEntityConfiguration documentUnitEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_DOCUMENTUNIT_ENDPOINT_NAME)).Value; HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration(); customHttpConfiguration.Addresses.Add(webApiAddress); WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint { AddressName = webApiAddress.AddressName, ControllerName = documentUnitEndpoint.ODATAControllerName, EndpointName = ODATA_DOCUMENTUNIT_ENDPOINT_NAME }; customHttpConfiguration.EndPoints.Add(endpoint); ODataModel <bool> result = WebAPIImpersonatorFacade.ImpersonateRawRequest <DocumentUnitEntities.DocumentUnit, ODataModel <bool> >(WebAPIHelper, odataFilter, customHttpConfiguration); if (result != null) { return(result.Value); } else { FileLogger.Warn(LogName.FileLog, string.Concat("HasViewableRight -> Document unit con id ", idDocumentUnit, " non trovata.")); return(false); } }
public IList <WebAPIDto <T> > GetAll() { List <WebAPIDto <T> > items = new List <WebAPIDto <T> >(); ICollection <T> results = null; foreach (IWebAPITenantConfiguration <T, TDao> configuration in _daoConfigurations) { try { WebAPIImpersonatorFacade.ImpersonateDao <TDao, T>(configuration.Dao, (impersonationType, dao) => { results = dao.GetAll(); items.AddRange(results.Select(s => _mapper.TransformDTO(s, configuration.Tenant))); }); } catch (Exception ex) { FileLogger.Error(Logger, string.Format(ERROR_MESSAGE, "GetAll", configuration.Tenant.TenantName), ex); throw new WebAPIException <List <WebAPIDto <T> > >(ex.Message, ex) { Results = items, TenantName = configuration.Tenant.TenantName }; } } return(items); }
public UDSDto GetUDSSource(Data.Entity.UDS.UDSRepository udsRepository, string odataFilter) { string controllerName = Utils.GetWebAPIControllerName(udsRepository.Name); IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.FirstOrDefault(x => x.AddressName.Eq(UDS_ADDRESS_NAME)); WebApiControllerEndpoint udsEndpoint = new WebApiControllerEndpoint { AddressName = UDS_ADDRESS_NAME, ControllerName = controllerName, EndpointName = "UDSModel" }; HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration(); customHttpConfiguration.Addresses.Add(webApiAddress); customHttpConfiguration.EndPoints.Add(udsEndpoint); odataFilter = string.Concat("?", odataFilter, "&applySecurity='0'"); string jsonSource = WebAPIImpersonatorFacade.ImpersonateRawRequest <UDSModel, string>(WebAPIHelper, odataFilter, customHttpConfiguration); if (string.IsNullOrEmpty(jsonSource)) { return(null); } return(ReadUDSJson(jsonSource, udsRepository)); }
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(); }
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(); }
public void Delete(T entity) { TDao currentTenant = _daoConfigurations.Single(s => s.IsCurrent).Dao; WebAPIImpersonatorFacade.ImpersonateDao <TDao, T>(currentTenant, (impersonationType, dao) => { dao.Delete(ref entity); }); }
public void Update(T entity, string actionType = "") { TDao currentTenant = _daoConfigurations.Single(s => s.IsCurrent).Dao; WebAPIImpersonatorFacade.ImpersonateDao <TDao, T>(currentTenant, (impersonationType, dao) => { dao.Update(ref entity, actionType); }); }
public WebAPIDto <T> GetById(Guid id) { IWebAPITenantConfiguration <T, TDao> currentTenant = _daoConfigurations.Single(s => s.IsCurrent); return(WebAPIImpersonatorFacade.ImpersonateDao <TDao, T, WebAPIDto <T> >(currentTenant.Dao, (impersonationType, dao) => { return _mapper.TransformDTO(dao.GetById(id), currentTenant.Tenant); })); }
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()); }
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()); }
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()); }
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); } }
public DomainUserModel domainUserModel() { string odataFilter = $"/DomainUserService.GetCurrentRights()"; IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME)); TenantEntityConfiguration domainuserEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_DOMAINUSER_ENDPOINT_NAME)).Value; HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration(); customHttpConfiguration.Addresses.Add(webApiAddress); WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint { AddressName = webApiAddress.AddressName, ControllerName = domainuserEndpoint.ODATAControllerName, EndpointName = ODATA_DOMAINUSER_ENDPOINT_NAME }; customHttpConfiguration.EndPoints.Add(endpoint); DomainUserModel result = WebAPIImpersonatorFacade.ImpersonateRawRequest <DomainUser, DomainUserModel>(WebAPIHelper, odataFilter, customHttpConfiguration); return(result); }
public bool HasProcedureDistributionInsertRight(int idCategory) { string odataFilter = $"/FascicleService.HasProcedureDistributionInsertRight(idCategory={idCategory})"; IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME)); TenantEntityConfiguration fascicleEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_FASCICLE_ENDPOINT_NAME)).Value; HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration(); customHttpConfiguration.Addresses.Add(webApiAddress); WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint { AddressName = webApiAddress.AddressName, ControllerName = fascicleEndpoint.ODATAControllerName, EndpointName = ODATA_FASCICLE_ENDPOINT_NAME }; customHttpConfiguration.EndPoints.Add(endpoint); ODataModel <bool> result = WebAPIImpersonatorFacade.ImpersonateRawRequest <Fascicle, ODataModel <bool> >(WebAPIHelper, odataFilter, customHttpConfiguration); return(result.Value); }
public bool HasCollaborationViewableRight(int idCollaboration) { string odataFilter = $"/CollaborationService.HasViewableRight(idCollaboration={idCollaboration})"; IBaseAddress webApiAddress = DocSuiteContext.Current.CurrentTenant.WebApiClientConfig.Addresses.Single(x => x.AddressName.Eq(WebApiHttpClient.ODATA_ADDRESS_NAME)); TenantEntityConfiguration collaborationEndpoint = DocSuiteContext.Current.CurrentTenant.Entities.Single(x => x.Key.Eq(ODATA_COLLABORATION_ENDPOINT_NAME)).Value; HttpClientConfiguration customHttpConfiguration = new HttpClientConfiguration(); customHttpConfiguration.Addresses.Add(webApiAddress); WebApiControllerEndpoint endpoint = new WebApiControllerEndpoint { AddressName = webApiAddress.AddressName, ControllerName = collaborationEndpoint.ODATAControllerName, EndpointName = ODATA_COLLABORATION_ENDPOINT_NAME }; customHttpConfiguration.EndPoints.Add(endpoint); ODataModel <bool> result = WebAPIImpersonatorFacade.ImpersonateRawRequest <Collaboration, ODataModel <bool> >(WebAPIHelper, odataFilter, customHttpConfiguration); return(result.Value); }
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); }
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(); }
public int Count() { int count = 0; foreach (IWebAPITenantConfiguration <T, TDao> configuration in _daoConfigurations) { try { WebAPIImpersonatorFacade.ImpersonateDao <TDao, T>(configuration.Dao, (impersonationType, dao) => { count += dao.Count(); }); } catch (Exception ex) { FileLogger.Error(Logger, string.Format(ERROR_MESSAGE, "Count", configuration.Tenant.TenantName), ex); throw new WebAPIException <int>(ex.Message, ex) { Results = count }; } } return(count); }
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; })); }
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(); } } } }
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); }
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); }
/// <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); }