public IVmListItemsData <IVmPostalCode> GetPostalCodes(string searchedCode, bool onlyValid = true) { IReadOnlyList <IVmPostalCode> result = new List <IVmPostalCode>(); contextManager.ExecuteReader(unitOfWork => { var searchCode = searchedCode.ToLower(); var postalCodeRep = unitOfWork.CreateRepository <IPostalCodeRepository>(); var qry = postalCodeRep.All(); if (onlyValid) { qry = qry.Where(pc => pc.IsValid); } var resultTemp = unitOfWork.ApplyIncludes(qry, i => i.Include(j => j.PostalCodeNames)); if (!string.IsNullOrEmpty(searchCode)) { resultTemp = resultTemp .Where(x => x.Code.ToLower().Contains(searchedCode) || x.PostalCodeNames.Any(y => y.Name.ToLower().Contains(searchedCode)) ) .OrderBy(x => x.Code) .Take(CoreConstants.MaximumNumberOfAllItems); result = TranslationManagerToVm.TranslateAll <PostalCode, VmPostalCode>(resultTemp); } }); return(new VmListItemsData <IVmPostalCode> (result)); }
private IReadOnlyList <VmJsonTypeName> GetMunicipalityNames(IUnitOfWork unitOfWork) { var rep = unitOfWork.CreateRepository <IMunicipalityNameRepository>(); var data = unitOfWork.ApplyIncludes(rep.All(), q => q.Include(x => x.Localization)); return(TranslationManagerToVm.TranslateAll <MunicipalityName, VmJsonTypeName>(data)); }
public VmFormState Save(VmFormState formState) { VmFormState result = null; contextManager.ExecuteWriter(unitOfWork => { var formStateRepository = unitOfWork.CreateRepository <IFormStateRepository>(); var isExistingFormState = formState.Id != null; if (isExistingFormState) { var existingFormState = formStateRepository.All() .Where(x => x.Id == new Guid(formState.Id)) .FirstOrDefault(); existingFormState.State = formState.State; unitOfWork.Save(); result = TranslationManagerToVm.Translate <FormState, VmFormState>(existingFormState); } else { var formStateToSave = TranslationManagerToEntity.Translate <VmFormState, FormState>(formState, unitOfWork); formStateRepository.Add(formStateToSave); unitOfWork.Save(); result = TranslationManagerToVm.Translate <FormState, VmFormState>(formStateToSave); } }); return(result); }
public IVmOpenApiGuidPageVersionBase GetServiceCollections(DateTime?date, int pageNumber, int pageSize, bool archived) { var vm = new V3VmOpenApiGuidPage(pageNumber, pageSize); if (pageNumber <= 0) { return(vm); } List <ServiceCollectionVersioned> collections = null; contextManager.ExecuteReader(unitOfWork => { if (archived) { collections = GetArchivedEntities <ServiceCollectionVersioned, ServiceCollection, ServiceCollectionLanguageAvailability>(vm, date, unitOfWork, q => q.Include(i => i.ServiceCollectionNames)); } else { collections = GetPublishedEntities <ServiceCollectionVersioned, ServiceCollection, ServiceCollectionLanguageAvailability>(vm, date, unitOfWork, q => q.Include(i => i.ServiceCollectionNames)); } }); if (collections?.Count > 0) { vm.ItemList = TranslationManagerToVm.TranslateAll <ServiceCollectionVersioned, VmOpenApiItem>(collections).ToList(); } return(vm); }
private IVmOpenApiFintoItemVersionBase GetFintoItemByUri <T>(string uri) where T : FintoItemBase { var result = new VmOpenApiFintoItemVersionBase(); contextManager.ExecuteReader(unitOfWork => { var rep = unitOfWork.CreateRepository <IRepository <T> >(); result = TranslationManagerToVm.TranslateFirst <T, VmOpenApiFintoItemVersionBase>(rep.All().Where(x => x.Uri == uri)); }); return(result); }
public VmKeywordSearchOutput KeywordSearch(VmKeywordSearch model, IUnitOfWork unitOfWork) { var localizationId = languageCache.Get(model.LocalizationCode); var keywordRep = unitOfWork.CreateRepository <IKeywordRepository>(); var name = model.Name.ToLower(); var keywords = keywordRep.All().Where(i => i.Name.ToLower().Contains(name) && i.LocalizationId == localizationId).OrderBy(i => i.Name).Take(CoreConstants.MaximumNumberOfAllItems + 1).ToList(); return(new VmKeywordSearchOutput() { Keywords = TranslationManagerToVm.TranslateAll <Keyword, VmKeywordItem>(keywords.Take(CoreConstants.MaximumNumberOfAllItems)), MoreAvailable = keywords.Count > CoreConstants.MaximumNumberOfAllItems }); }
public VmFormState GetById(string id) { VmFormState result = null; contextManager.ExecuteWriter(unitOfWork => { var formStateRepository = unitOfWork.CreateRepository <IFormStateRepository>(); var _formState = formStateRepository .All() .Where(formState => formState.Id == new Guid(id)).FirstOrDefault(); result = TranslationManagerToVm.Translate <FormState, VmFormState>(_formState); }); return(result); }
private void AddConnectionsInfo(VmServiceOutput result, ICollection <ServiceServiceChannel> connections, IUnitOfWork unitOfWork) { var serviceUnificId = result.UnificRootId; var psPublished = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString()); var psDraft = typesCache.Get <PublishingStatusType>(PublishingStatus.Draft.ToString()); var psModified = typesCache.Get <PublishingStatusType>(PublishingStatus.Modified.ToString()); var connectedChannelsUnificIds = result.ConnectedChannels.Select(i => i.ChannelId).ToList(); var channelRep = unitOfWork.CreateRepository <IServiceChannelVersionedRepository>(); var connectedChannels = channelRep.All().Where(i => (connectedChannelsUnificIds.Contains(i.UnificRootId)) && (i.PublishingStatusId == psPublished || i.PublishingStatusId == psDraft || i.PublishingStatusId == psModified)) .Include(i => i.ServiceChannelNames).Include(i => i.LanguageAvailabilities) .ToList() // could be done on db when it will be implemented in EF .GroupBy(i => i.UnificRootId) .Select(i => i.FirstOrDefault(x => x.PublishingStatusId == psPublished) ?? i.FirstOrDefault()) .Select(i => { var modifiedData = result.ConnectedChannels.FirstOrDefault(m => m.ChannelId == i.UnificRootId); var originalConnection = connections.FirstOrDefault(x => x.ServiceId == serviceUnificId && x.ServiceChannelId == i.UnificRootId); return(new ServiceServiceChannel() { ServiceChannelId = i.UnificRootId, ServiceId = serviceUnificId, ServiceServiceChannelDescriptions = originalConnection?.ServiceServiceChannelDescriptions ?? new List <ServiceServiceChannelDescription>(), ServiceServiceChannelDigitalAuthorizations = originalConnection?.ServiceServiceChannelDigitalAuthorizations ?? new List <ServiceServiceChannelDigitalAuthorization>(), IsASTIConnection = originalConnection?.IsASTIConnection ?? false, ServiceServiceChannelExtraTypes = originalConnection?.ServiceServiceChannelExtraTypes ?? new List <ServiceServiceChannelExtraType>(), ChargeTypeId = originalConnection?.ChargeTypeId, ServiceChannel = new ServiceChannel() { Id = i.UnificRootId, Versions = new List <ServiceChannelVersioned>() { i } }, Modified = modifiedData?.Modified ?? DateTime.MinValue, ModifiedBy = modifiedData?.ModifiedBy ?? string.Empty }); }).ToList(); result.Connections = TranslationManagerToVm.TranslateAll <ServiceServiceChannel, VmConnectionOutput>(connectedChannels).InclusiveToList(); result.NumberOfConnections = result.Connections.Count; }
public VmAddressSimpleBase GetAddress(VmGetCoordinatesForAddressIn model) { if (!model.Id.IsAssigned()) { return(null); } VmAddressSimpleBase result = null; contextManager.ExecuteReader(unitOfWork => { var addressQuery = unitOfWork.CreateRepository <IAddressRepository>().All().Where(x => x.Id == model.Id); var address = unitOfWork.ApplyIncludes(addressQuery, q => q .Include(x => x.Coordinates)).FirstOrDefault(); TranslationManagerToVm.SetLanguage(model.Language); result = address != null ? TranslationManagerToVm.Translate <Address, VmAddressSimpleBase>(address) : null; }); return(result); }
public VmAnnotations GetAnnotations(ServiceInfo serviceInfo) { var annotationResult = annotationProvider.GetAnnotations(serviceInfo); if (annotationResult.Result != null) { switch (annotationResult.Result.State) { case AnnotationStates.Ok: var uris = annotationResult.Result?.Annotations.Select(x => x.Uri); return(contextManager.ExecuteReader(unitOfWork => { LanguageCode language; if (!Enum.TryParse <LanguageCode>(serviceInfo.LanguageCode, out language)) { language = LanguageCode.fi; } var exactMatchRep = unitOfWork.CreateRepository <IOntologyTermExactMatchRepository>(); var exactMatches = exactMatchRep.All().Where(x => uris.Contains(x.ExactMatch.Uri.ToLower())).Select(x => x.OntologyTermId).ToList(); var ontoRep = unitOfWork.CreateRepository <IOntologyTermRepository>(); var ontos = GetIncludesForFinto <OntologyTerm, OntologyTermName>(unitOfWork, ontoRep.All().Where(i => exactMatches.Contains(i.Id))); return new VmAnnotations() { Id = serviceInfo.Id, Language = language, AnnotationOntologyTerms = TranslationManagerToVm.TranslateAll <IFintoItemBase, VmListItem>(ontos).ToList() }; })); case AnnotationStates.EmptyInputReceived: throw new PtvAppException("Annotation failed", messageAnnotationEmpty); default: throw new PtvAppException("Annotation failed", messageAnnotationFailed); } } else { throw new PtvAppException("Annotation failed", messageAnnotationFailed); } }
private VmConnectionsOutput GetRelations(IUnitOfWork unitOfWork, VmConnectionsInput model) { var serviceRep = unitOfWork.CreateRepository <IServiceRepository>(); var unificRootId = versioningManager.GetUnificRootId <ServiceVersioned>(unitOfWork, model.Id); if (unificRootId.HasValue) { var service = serviceRep.All() .Include(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceChannel).ThenInclude(j => j.Versions).ThenInclude(j => j.ServiceChannelNames) .Include(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceChannel).ThenInclude(j => j.Versions).ThenInclude(j => j.LanguageAvailabilities) .Include(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceServiceChannelDescriptions) .Include(j => j.ServiceServiceChannels).ThenInclude(j => j.ServiceServiceChannelDigitalAuthorizations).ThenInclude(j => j.DigitalAuthorization) .Single(x => x.Id == unificRootId.Value); var result = TranslationManagerToVm.Translate <Service, VmConnectionsOutput>(service); result.Id = model.Id; return(result); } return(null); }
public IVmListItemsData <VmListItem> Search(IVmGetFilteredTree vmGetFilteredTree) { var treeType = Enum.Parse(typeof(TreeTypeEnum), vmGetFilteredTree.TreeType); IEnumerable <IFintoItemBase> searchResult = null; contextManager.ExecuteReader(unitOfWork => { switch ((TreeTypeEnum)treeType) { case TreeTypeEnum.ServiceClass: searchResult = SearchFintoList <ServiceClass, ServiceClassName>(unitOfWork, vmGetFilteredTree.SearchValue); break; case TreeTypeEnum.IndustrialClass: searchResult = SearchFintoList <IndustrialClass, IndustrialClassName>(unitOfWork, vmGetFilteredTree.SearchValue, industrialClassLevel); break; case TreeTypeEnum.OntologyTerm: searchResult = SearchFintoList <OntologyTerm, OntologyTermName>(unitOfWork, vmGetFilteredTree.SearchValue, languages: vmGetFilteredTree.Languages); break; case TreeTypeEnum.LifeEvent: searchResult = SearchFintoList <LifeEvent, LifeEventName>(unitOfWork, vmGetFilteredTree.SearchValue); break; case TreeTypeEnum.DigitalAuthorization: searchResult = SearchFintoList <DigitalAuthorization, DigitalAuthorizationName>(unitOfWork, vmGetFilteredTree.SearchValue); break; default: searchResult = new List <IFintoItem>(); break; } }); var result = new VmListItemsData <VmListItem>(TranslationManagerToVm.TranslateAll <IFintoItemBase, VmListItem>(searchResult.ToList()).ToList()); return(result); }
public VmFormState Search(VmFormStateSearch search) { VmFormState result = null; contextManager.ExecuteWriter(unitOfWork => { var formStateRepository = unitOfWork.CreateRepository <IFormStateRepository>(); var _formState = formStateRepository .All() .Where(formState => formState.EntityId == search.EntityId && formState.EntityType == search.EntityType && formState.LanguageId == search.LanguageId && formState.UserName == search.UserName ) .FirstOrDefault(); result = TranslationManagerToVm.Translate <FormState, VmFormState>(_formState); }); return(result ?? new VmFormState() { Exists = false }); }
public IVmOpenApiGuidPageVersionBase GetPostalCodeList(int pageNumber, int pageSize) { var vm = new VmOpenApiCodeListPage(pageNumber, pageSize); if (pageNumber <= 0) { return(vm); } List <PostalCode> postalCodes = null; contextManager.ExecuteReader(unitOfWork => { postalCodes = GetEntitiesForPage <PostalCode>(vm, unitOfWork, q => q.Include(j => j.PostalCodeNames), keySelector: x => x.Code); }); if (postalCodes?.Count > 0) { vm.ItemList = TranslationManagerToVm.TranslateAll <PostalCode, VmOpenApiCodeListItem>(postalCodes).ToList(); } return(vm); }
public VmChannelRelation GetRelationDetail(VmGetRelationDetail model) { VmChannelRelation result = null; contextManager.ExecuteReader(unitOfWork => { TranslationManagerToVm.SetLanguage(model.Language); var relationRep = unitOfWork.CreateRepository <IServiceServiceChannelRepository>(); var resultTemp = unitOfWork.ApplyIncludes(relationRep.All().Where(x => (x.ServiceId == model.ServiceId.Value && x.ServiceChannelId == model.ChannelId.Value)), i => i .Include(j => j.ServiceChannel).ThenInclude(j => j.Versions).ThenInclude(j => j.ServiceChannelNames).ThenInclude(j => j.Type) .Include(j => j.ServiceChannel).ThenInclude(j => j.Versions).ThenInclude(j => j.Type) .Include(j => j.ServiceServiceChannelDescriptions).ThenInclude(j => j.Type) .Include(j => j.ServiceServiceChannelDigitalAuthorizations).ThenInclude(j => j.DigitalAuthorization), true).FirstOrDefault(); if (resultTemp != null) { result = TranslationManagerToVm.Translate <ServiceServiceChannel, VmChannelRelation>(resultTemp); result.Id = model.ChannelRelationId; } }); return(result); }
private IList <IVmOpenApiServiceCollectionVersionBase> GetServiceCollectionsWithDetails(IUnitOfWork unitOfWork, List <Guid> versionIdList, int openApiVersion, bool getOnlyPublished = true) { if (versionIdList.Count == 0) { return(new List <IVmOpenApiServiceCollectionVersionBase>()); } var serviceCollectionRep = unitOfWork.CreateRepository <IServiceCollectionVersionedRepository>(); var publishedId = PublishingStatusCache.Get(PublishingStatus.Published); var resultTemp = unitOfWork.ApplyIncludes(serviceCollectionRep.All().Where(s => versionIdList.Contains(s.Id)), q => //q.Include(i => i.ServiceCollectionLanguages).ThenInclude(i => i.Language) q.Include(i => i.ServiceCollectionNames) .Include(i => i.ServiceCollectionDescriptions) .Include(i => i.ServiceCollectionServices).ThenInclude(i => i.Service).ThenInclude(i => i.Versions) .Include(i => i.LanguageAvailabilities) .Include(i => i.Organization).ThenInclude(i => i.Versions) .OrderByDescending(i => i.Modified)); // Filter out items that do not have language versions published! var serviceCollections = getOnlyPublished ? resultTemp.Where(c => c.LanguageAvailabilities.Any(l => l.StatusId == publishedId)).ToList() : resultTemp.ToList(); // Find only published services for service collections var publishedServices = serviceCollections.SelectMany(i => i.ServiceCollectionServices).Select(i => i.Service).SelectMany(i => i.Versions) .Where(i => i.PublishingStatusId == publishedId).ToList(); var publishedServiceIds = publishedServices.Select(i => i.Id).ToList(); var publishedServiceRootIds = new List <Guid>(); if (publishedServiceIds.Count > 0) { var servicenRep = unitOfWork.CreateRepository <IServiceVersionedRepository>(); publishedServiceRootIds = servicenRep.All().Where(c => publishedServiceIds.Contains(c.Id)) .Where(s => s.LanguageAvailabilities.Any(l => l.StatusId == publishedId)) // Filter out services with no language versions published .Select(c => c.UnificRootId).ToList(); } serviceCollections.ForEach(serviceCollection => { // Filter out not published services serviceCollection.ServiceCollectionServices = serviceCollection.ServiceCollectionServices.Where(c => publishedServiceRootIds.Contains(c.ServiceId)).ToList(); // Filter out not published language versions if (getOnlyPublished) { var notPublishedLanguageVersions = serviceCollection.LanguageAvailabilities.Where(l => l.StatusId != publishedId).Select(l => l.LanguageId).ToList(); if (notPublishedLanguageVersions.Count > 0) { serviceCollection.ServiceCollectionNames = serviceCollection.ServiceCollectionNames.Where(i => !notPublishedLanguageVersions.Contains(i.LocalizationId)).ToList(); serviceCollection.ServiceCollectionDescriptions = serviceCollection.ServiceCollectionDescriptions.Where(i => !notPublishedLanguageVersions.Contains(i.LocalizationId)).ToList(); } } }); // Fill with service names (only type: Name) var serviceNames = unitOfWork.CreateRepository <IServiceNameRepository>().All() .Where(i => publishedServiceIds.Contains(i.ServiceVersionedId) && i.TypeId == typesCache.Get <NameType>(NameTypeEnum.Name.ToString())) .GroupBy(i => i.ServiceVersionedId).ToDictionary(i => i.Key, i => i.ToList()); // Fill with service descriptions (only type: Description) var serviceDescriptions = unitOfWork.CreateRepository <IServiceDescriptionRepository>().All() .Where(i => publishedServiceIds.Contains(i.ServiceVersionedId) && i.TypeId == typesCache.Get <DescriptionType>(DescriptionTypeEnum.Description.ToString())) .GroupBy(i => i.ServiceVersionedId).ToDictionary(i => i.Key, i => i.ToList()); // Get language availabilities for published services var serviceLanguageAvailabilities = unitOfWork.CreateRepository <IServiceLanguageAvailabilityRepository>().All() .Where(i => publishedServiceIds.Contains(i.ServiceVersionedId) && i.StatusId == publishedId) .GroupBy(i => i.ServiceVersionedId) .ToDictionary(i => i.Key, i => i.Select(l => l.LanguageId).ToList()); // Filter out name and description language versions that are not available publishedServices.ForEach(s => { var availableLanguages = serviceLanguageAvailabilities.TryGet(s.Id); if (availableLanguages?.Count > 0) { s.ServiceNames = serviceNames.TryGet(s.Id)?.Where(n => availableLanguages.Contains(n.LocalizationId)).ToList(); s.ServiceDescriptions = serviceDescriptions?.TryGet(s.Id).Where(n => availableLanguages.Contains(n.LocalizationId)).ToList(); } }); var result = TranslationManagerToVm.TranslateAll <ServiceCollectionVersioned, VmOpenApiServiceCollectionVersionBase>(serviceCollections).ToList(); if (result == null) { throw new Exception(CoreMessages.OpenApi.RecordNotFound); } // Get the right open api view model version var versionList = new List <IVmOpenApiServiceCollectionVersionBase>(); result.ForEach(serviceCollection => { // Get the sourceId if user is logged in var userId = utilities.GetRelationIdForExternalSource(false); if (!string.IsNullOrEmpty(userId)) { serviceCollection.SourceId = GetSourceId <ServiceCollection>(serviceCollection.Id.Value, userId, unitOfWork); } versionList.Add(GetEntityByOpenApiVersion(serviceCollection as IVmOpenApiServiceCollectionVersionBase, openApiVersion)); }); return(versionList); }
public VmConnectableServiceSearchResult GetConnectableService(VmConnectableServiceSearch search) { search.Name = search.Name != null ? search.Name.Trim() : search.Name; return(ContextManager.ExecuteReader(unitOfWork => { var languageCode = SetTranslatorLanguage(search); var selectedLanguageId = languageCache.Get(languageCode.ToString()); var nameTypeId = typesCache.Get <NameType>(NameTypeEnum.Name.ToString()); var publishedStatusId = PublishingStatusCache.Get(PublishingStatus.Published); var draftStatusId = PublishingStatusCache.Get(PublishingStatus.Draft); var notCommonId = typesCache.Get <ServiceChannelConnectionType>(ServiceChannelConnectionTypeEnum.NotCommon.ToString()); var languagesIds = new List <Guid>() { selectedLanguageId }; var serviceRep = unitOfWork.CreateRepository <IServiceVersionedRepository>(); var generalDescriptionRep = unitOfWork.CreateRepository <IStatutoryServiceGeneralDescriptionVersionedRepository>(); var resultTemp = serviceRep.All(); #region SearchByFilterParam if (search.Type == DomainEnum.Channels) { var channelRep = unitOfWork.CreateRepository <IServiceChannelVersionedRepository>(); var channel = channelRep.All().FirstOrDefault(x => x.Id == search.Id); if (channel?.ConnectionTypeId == notCommonId) { resultTemp = resultTemp .Where(x => (x.OrganizationId == channel.OrganizationId)); } var languageAvaliabilitiesRep = unitOfWork.CreateRepository <IServiceChannelLanguageAvailabilityRepository>(); languagesIds = languageAvaliabilitiesRep.All() .Where(x => x.ServiceChannelVersionedId == search.Id) .Select(x => x.LanguageId).ToList(); } if (search.OrganizationId.HasValue) { resultTemp = resultTemp .Where( x => x.OrganizationServices .Any(o => o.OrganizationId == search.OrganizationId) || x.OrganizationId == search.OrganizationId.Value ); } if (!string.IsNullOrEmpty(search.Name)) { var rootId = GetRootIdFromString(search.Name); if (!rootId.HasValue) { var searchText = search.Name.ToLower(); resultTemp = resultTemp .Where( x => x.ServiceNames.Any(y => y.Name.ToLower().Contains(searchText)) ); } else { resultTemp = resultTemp .Where(service => service.UnificRootId == rootId ); } } else { resultTemp = resultTemp.Where( x => x.ServiceNames.Any( y => !string.IsNullOrEmpty(y.Name))); } if (search.ServiceTypeId.HasValue) { var generalDescIds = generalDescriptionRep.All() .Where(x => x.TypeId == search.ServiceTypeId && x.PublishingStatusId == publishedStatusId) .Select(x => x.UnificRootId); resultTemp = resultTemp .Where(x => (x.TypeId == search.ServiceTypeId.Value && x.StatutoryServiceGeneralDescriptionId == null) || generalDescIds.Any(d => d == x.StatutoryServiceGeneralDescriptionId)); } //commonService.ExtendPublishingStatusesByEquivalents(search.SelectedPublishingStatuses); resultTemp = resultTemp.WherePublishingStatusIn(new List <Guid>() { publishedStatusId, draftStatusId }); resultTemp = resultTemp.Where(x => x.LanguageAvailabilities.Select(y => y.LanguageId).Any(l => languagesIds.Contains(l))); #endregion SearchByFilterParam resultTemp = resultTemp // .Include(sv => sv.OrganizationServices) // .Include(sv => sv.ServiceNames) .Include(sv => sv.StatutoryServiceGeneralDescription) .ThenInclude(ssgd => ssgd.Versions) // .Include(sv => sv.Type) .Include(sv => sv.LanguageAvailabilities) .ThenInclude(sla => sla.Language); var rowCount = resultTemp.Count(); var pageNumber = search.PageNumber.PositiveOrZero(); var resultTempData = resultTemp.Select(i => new { Id = i.Id, ServiceVersioned = i, UnificRootId = i.UnificRootId, // Name = i.ServiceNames // .OrderBy(x => x.Localization.OrderNumber) // .FirstOrDefault(x => selectedLanguageId == x.LocalizationId && x.TypeId == nameTypeId).Name, // AllNames = i.ServiceNames // .Where(x => x.TypeId == typesCache.Get<NameType>(NameTypeEnum.Name.ToString())) // .Select(x => new { x.LocalizationId, x.Name }), Modified = i.Modified, // required for sorting ModifiedBy = i.ModifiedBy // required for sorting }) .OrderByDescending(i => i.Modified) .ApplyPaging(pageNumber); var serviceIds = resultTempData.Data.Select(i => i.Id).ToList(); var serviceNameRep = unitOfWork.CreateRepository <IServiceNameRepository>(); var serviceNames = serviceNameRep.All().Where(x => serviceIds.Contains(x.ServiceVersionedId) && x.TypeId == nameTypeId).OrderBy(i => i.Localization.OrderNumber).Select(i => new { i.ServiceVersionedId, i.Name, i.LocalizationId }).ToList().GroupBy(i => i.ServiceVersionedId) .ToDictionary(i => i.Key, i => i.ToDictionary(x => languageCache.GetByValue(x.LocalizationId), x => x.Name)); var result = resultTempData.Data.Select(i => { Guid?typeId = null; if (i.ServiceVersioned?.TypeId != null) { typeId = i.ServiceVersioned.TypeId.Value; } else if (i.ServiceVersioned.StatutoryServiceGeneralDescription?.Versions?.Count > 0) { var ssgdv = versioningManager.ApplyPublishingStatusFilterFallback(i.ServiceVersioned.StatutoryServiceGeneralDescription.Versions); typeId = ssgdv?.TypeId; } return new VmConnectableService { Id = i.Id, UnificRootId = i.UnificRootId, Name = serviceNames.TryGetOrDefault(i.Id, new Dictionary <string, string>()), ServiceTypeId = typeId, ServiceType = typeId == null ? string.Empty : typesCache.GetByValue <ServiceType>(typeId.Value), LanguagesAvailabilities = TranslationManagerToVm.TranslateAll <ILanguageAvailability, VmLanguageAvailabilityInfo>(i.ServiceVersioned.LanguageAvailabilities), OrganizationId = i.ServiceVersioned.OrganizationId, Modified = i.ServiceVersioned.Modified.ToEpochTime(), ModifiedBy = i.ServiceVersioned.ModifiedBy }; }) .ToList(); return new VmConnectableServiceSearchResult() { Data = result, MoreAvailable = resultTempData.MoreAvailable, Count = rowCount, PageNumber = pageNumber }; })); }
private IReadOnlyList <VmJsonTypeName> GetTranslationData <TEntity>(IUnitOfWork unitOfWork) where TEntity : INameReference { var rep = unitOfWork.CreateRepository <IRepository <TEntity> >(); return(TranslationManagerToVm.TranslateAll <INameReference, VmJsonTypeName>(rep.All().Cast <INameReference>())); }
public List <IVmBase> SaveServiceAndChannels(VmRelations relations) { var result = new List <IVmBase>(); Dictionary <Guid, Guid> serviceVersion = new Dictionary <Guid, Guid>(); contextManager.ExecuteWriter(unitOfWork => { IQueryable <Guid> supportedChannelIds = null; var userOrgs = userOrganizationService.GetUserCompleteOrgStructure(unitOfWork); if (userOrganizationService.UserHighestRole(userOrgs) != UserRoleEnum.Eeva) { var schvRep = unitOfWork.CreateRepository <IServiceChannelVersionedRepository>(); var userOrgsIds = userOrgs.SelectMany(i => i).Select(i => i.OrganizationId).ToList(); var psPublished = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString()); var psCommonForAll = typesCache.Get <ServiceChannelConnectionType>(ServiceChannelConnectionTypeEnum.CommonForAll.ToString()); var channelIds = relations.ServiceAndChannelRelations.SelectMany(r => r.ChannelRelations).Select(ch => ch.ConnectedChannel.Id); var channels = schvRep.All().Where(i => channelIds.Contains(i.Id)); var supportedChannels = channels.Where(ch => (userOrgsIds.Contains(ch.OrganizationId) || (ch.PublishingStatusId == psPublished && ch.ConnectionTypeId == psCommonForAll))); supportedChannelIds = supportedChannels.Select(ch => ch.UnificRootId); } SetTranslatorLanguage(relations); relations.ServiceAndChannelRelations = relations.ServiceAndChannelRelations.Distinct(new RelationComparer()).ToList(); relations.ServiceAndChannelRelations.ForEach(i => i.ChannelRelations = i.ChannelRelations.Distinct(new RelationChannelsComparer()).ToList()); var serviceVersionedRep = unitOfWork.CreateRepository <IServiceVersionedRepository>(); var serviceVersionedIds = relations.ServiceAndChannelRelations.Select(sv => sv.Id).ToList(); var unificRootIds = serviceVersionedRep.All().Where(sv => serviceVersionedIds.Contains(sv.Id)).ToDictionary(k => k.Id, v => v.UnificRootId); foreach (var item in relations.ServiceAndChannelRelations) { if (!item.Id.IsAssigned() || !unificRootIds.ContainsKey(item.Id.Value)) { continue; } item.UnificRootId = unificRootIds[item.Id.Value]; item.ChannelRelations.ForEach(chs => chs.Service = unificRootIds[item.Id.Value]); } var relationData = TranslationManagerToEntity.TranslateAll <VmServiceChannelRelation, Service>(relations.ServiceAndChannelRelations, unitOfWork); serviceVersion = unitOfWork.TranslationCloneCache.GetFromCachedSet <ServiceVersioned>().ToDictionary(i => i.OriginalEntity.Id, i => i.ClonedEntity.Id); foreach (var service in relationData) { var supportedServiceServiceChannels = supportedChannelIds == null ? service.ServiceServiceChannels : service.ServiceServiceChannels.Where(ch => supportedChannelIds.Contains(ch.ServiceChannelId)).ToList(); service.ServiceServiceChannels = dataUtils.UpdateCollectionForReferenceTable(unitOfWork, supportedServiceServiceChannels, query => query.ServiceId == service.Id, channel => channel.ServiceChannelId); UpdateDigitalAuthorizationCollection(unitOfWork, service.ServiceServiceChannels); } unitOfWork.Save(); }); contextManager.ExecuteReader(unitOfWork => { var serviceCloneData = new Dictionary <Guid, string>(); relations.ServiceAndChannelRelations.ForEach(service => { if (serviceVersion.ContainsKey(service.Id.Value)) { serviceCloneData.Add(serviceVersion[service.Id.Value], service.ConnectedServiceId); } }); var cloneServiceIds = serviceCloneData.Select(y => y.Key).ToList(); var serviceRep = unitOfWork.CreateRepository <IServiceVersionedRepository>(); var resultTemp = unitOfWork.ApplyIncludes(serviceRep.All().Where(x => cloneServiceIds.Contains(x.Id)), q => q.Include(i => i.ServiceNames).ThenInclude(i => i.Type) .Include(i => i.UnificRoot).ThenInclude(i => i.ServiceServiceChannels).ThenInclude(i => i.ServiceChannel).ThenInclude(i => i.Versions).ThenInclude(i => i.ServiceChannelNames).ThenInclude(i => i.Type) .Include(i => i.UnificRoot).ThenInclude(i => i.ServiceServiceChannels).ThenInclude(i => i.ServiceChannel).ThenInclude(i => i.Versions).ThenInclude(i => i.Type) .Include(i => i.UnificRoot).ThenInclude(i => i.ServiceServiceChannels).ThenInclude(i => i.ServiceServiceChannelDescriptions).ThenInclude(i => i.Type) .Include(i => i.UnificRoot).ThenInclude(i => i.ServiceServiceChannels).ThenInclude(i => i.ServiceServiceChannelDigitalAuthorizations).ThenInclude(i => i.DigitalAuthorization) ); var cloneServices = TranslationManagerToVm.TranslateAll <ServiceVersioned, VmServiceRelationListItem>(resultTemp).Cast <IVmServiceListItem>().ToList(); cloneServices.ForEach(service => { if (serviceCloneData.ContainsKey(service.Id)) { result.Add(new VmConnectedService() { UiId = serviceCloneData[service.Id], Service = service }); } }); }); return(result); }