public GetOrganizationByIdTests()
 {
     _organizationList            = EntityGenerator.GetOrganizationEntityList(1, PublishingStatusCache);
     _publishedOrganization       = _organizationList.Where(o => o.PublishingStatusId == PublishedId).FirstOrDefault();
     _publishedOrganizationId     = _publishedOrganization.Id;
     _publishedOrganizationRootId = _publishedOrganization.UnificRootId;
 }
Exemple #2
0
        /// <summary>
        /// Tries to get organization display name in Finnish and then fallbacks to other languages.
        /// </summary>
        /// <param name="organization">instance of OrganizationVersioned</param>
        /// <returns>Organization display name if found, otherwise null.</returns>
        private static string GetOrganizationDisplayName(OrganizationVersioned organization)
        {
            string orgDisplayName = null;

            if (organization != null && organization.OrganizationNames != null && organization.OrganizationNames.Count > 0 && organization.OrganizationDisplayNameTypes != null && organization.OrganizationDisplayNameTypes.Count > 0)
            {
                // assumption is that fi language code is always returned first as specified in the enum
                var languageCodes = Enum.GetNames(typeof(LanguageCode));

                Guid?  displayNameType = null;
                string languageCode    = null;

                foreach (var lc in languageCodes)
                {
                    displayNameType = organization.OrganizationDisplayNameTypes.FirstOrDefault(type => type.Localization.Code == lc)?.DisplayNameTypeId;

                    if (displayNameType.HasValue)
                    {
                        // found displaynametype for a language, exit the foreach
                        languageCode = lc;
                        break;
                    }
                }

                // just a check that a displaynametype has been found for some language, try to get the displayname with type and language
                if (displayNameType.HasValue)
                {
                    orgDisplayName = organization.OrganizationNames.FirstOrDefault(orgName => orgName.TypeId == displayNameType.Value && orgName.Localization.Code == languageCode)?.Name;
                }
            }

            return(orgDisplayName);
        }
        public override V6VmOpenApiServiceOrganization TranslateEntityToVm(OrganizationService entity)
        {
            // These are all other responsible organizations
            var definition = CreateBaseEntityVmDefinitions(entity)
                             .AddNavigation(i => "OtherResponsible", o => o.RoleType);

            if (entity.Organization != null && entity.Organization.Versions?.Count > 0)
            {
                var publishedId = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString());
                definition.AddNavigation(i => i.Organization.Versions.FirstOrDefault(x => x.PublishingStatusId == publishedId), o => o.Organization);
            }
            else if (entity.OrganizationId.IsAssigned())
            {
                var organization = new OrganizationVersioned()
                {
                    UnificRootId = entity.OrganizationId
                };
                definition.AddNavigation(i => organization, o => o.Organization);
            }
            else
            {
                definition.AddNavigation(i => (OrganizationVersioned)null, o => o.Organization);
            }

            return(definition.GetFinal());
        }
        private void CheckTranslations(IVmOpenApiOrganizationInVersionBase source, OrganizationVersioned target)
        {
            target.OrganizationNames.First().Name.Should().Be(TestDataFactory.TEXT);

            // organization emails
            source.EmailAddresses.Count.Should().Be(target.OrganizationEmails.Count);
            AssertEmail(
                source.EmailAddresses.Single(e => e.Language == LanguageCode.fi.ToString()),
                target.OrganizationEmails.Single(e => e.Email.LocalizationId == fiId).Email
                );
            AssertEmail(
                source.EmailAddresses.Single(e => e.Language == LanguageCode.sv.ToString()),
                target.OrganizationEmails.Single(e => e.Email.LocalizationId == svId).Email
                );

            // organization phones
            source.PhoneNumbers.Count.Should().Be(target.OrganizationPhones.Count);
            AssertPhone(
                source.PhoneNumbers.Single(p => p.Language == LanguageCode.fi.ToString()),
                target.OrganizationPhones.Single(p => p.Phone.LocalizationId == fiId).Phone
                );
            AssertPhone(
                source.PhoneNumbers.Single(p => p.Language == LanguageCode.sv.ToString()),
                target.OrganizationPhones.Single(p => p.Phone.LocalizationId == svId).Phone
                );
        }
        protected T GetOrganizationOriginalValue <T>(OrganizationVersioned entity, EntityEntry <IRoleBased> entityEntry, string propertyName, IUnitOfWorkWritable unitOfWork)
        {
            var cachedValue = unitOfWork.TranslationCloneCache.GetFromCachedSet <OrganizationVersioned>()
                              .Where(x => x.ClonedEntity.Id == entity.Id).Select(x => (T)x.OriginalEntity.GetItemValue(propertyName)).SingleOrDefault();

            return(cachedValue != null ? cachedValue : GetOriginalValue <T>(entityEntry, propertyName));
        }
        private ServiceVersioned CreateService()
        {
            var psPublished  = CacheManager.PublishingStatusCache.Get(PublishingStatus.Published);
            var organization = new OrganizationVersioned()
            {
                PublishingStatusId = psPublished, UnificRoot = new Organization()
                {
                    Id = Guid.NewGuid()
                }, OrganizationNames = new List <OrganizationName>()
                {
                    new OrganizationName()
                    {
                        Name = "testOrganizationName", Type = new NameType()
                        {
                            Code = NameTypeEnum.Name.ToString()
                        }
                    }
                }
            };

            organization.UnificRoot.Versions.Add(organization);

            return(new ServiceVersioned()
            {
                Created = DateTime.Now,
                CreatedBy = "testCreator",
                Id = Guid.NewGuid(),
                TypeId = ServiceTypeEnum.Service.ToString().GetGuid(),
                ServiceNames = new List <ServiceName>()
                {
                    new ServiceName()
                    {
                        Name = "testServiceName", TypeId = NameTypeEnum.Name.ToString().GetGuid()
                    }
                },
                OrganizationServices = new List <OrganizationService> {
                    new OrganizationService {
                        OrganizationId = Guid.NewGuid(), Organization = organization.UnificRoot
                    }
                },
                ServiceServiceClasses = new List <ServiceServiceClass>()
                {
                    new ServiceServiceClass()
                    {
                        ServiceClass = new ServiceClass()
                        {
                            Label = "testServiceClasName 1"
                        }
                    },
                    new ServiceServiceClass()
                    {
                        ServiceClass = new ServiceClass()
                        {
                            Label = "testServiceClasName 2"
                        }
                    }
                },
            });
        }
        private void CheckTranslations(OrganizationVersioned source, IVmOpenApiOrganizationVersionBase target)
        {
            target.OrganizationNames.Count.Should().Be(1);
            target.Municipality.Name.FirstOrDefault().Value.Should().Be(source.Municipality.MunicipalityNames.FirstOrDefault().Name);
            target.OrganizationDescriptions.First().Value.Should().NotBeNull();
            target.OrganizationType.Should().Be(CacheManager.TypesCache.GetByValue <OrganizationType>(source.TypeId.Value));
            var targetAddress = target.Addresses.First();
            var sourceAddress = source.OrganizationAddresses.First();

            targetAddress.StreetAddress.Street.First().Value.Should().Be(sourceAddress.Address.AddressStreets.First().StreetNames.First().Name);
            targetAddress.Type.Should().Be(CacheManager.TypesCache.GetByValue <AddressCharacter>(sourceAddress.CharacterId));
            targetAddress.Country.Should().Be(sourceAddress.Address.Country.Code);
            target.WebPages.First().Value.Should().Be(source.OrganizationWebAddress.First().WebPage.Name);
            target.Services.Count.Should().Be(3);
            target.DisplayNameType.First().Type.Should().Be(CacheManager.TypesCache.GetByValue <NameType>(source.OrganizationDisplayNameTypes.First().DisplayNameTypeId));

            // check phones
            target.PhoneNumbers.Count.Should().Be(source.OrganizationPhones.Count);
            AssertPhone(
                target.PhoneNumbers.Single(p => p.Language == LanguageCode.fi.ToString()),
                source.OrganizationPhones.Single(p => p.Phone.LocalizationId == fiId).Phone
                );
            AssertPhone(
                target.PhoneNumbers.Single(p => p.Language == LanguageCode.sv.ToString()),
                source.OrganizationPhones.Single(p => p.Phone.LocalizationId == svId).Phone
                );

            // check emails
            target.EmailAddresses.Count.Should().Be(source.OrganizationEmails.Count);
            AssertEmail(
                target.EmailAddresses.Single(e => e.Language == LanguageCode.fi.ToString()),
                source.OrganizationEmails.Single(e => e.Email.LocalizationId == fiId).Email
                );
            AssertEmail(
                target.EmailAddresses.Single(e => e.Language == LanguageCode.sv.ToString()),
                source.OrganizationEmails.Single(e => e.Email.LocalizationId == svId).Email
                );
        }
        public override VmOpenApiItem TranslateEntityToVm(Organization entity)
        {
            var definition = CreateEntityViewModelDefinition <VmOpenApiItem>(entity);

            if (entity != null && entity.Versions?.Count > 0)
            {
                var publishedId = typesCache.Get <PublishingStatusType>(PublishingStatus.Published.ToString());
                definition.AddPartial(i => i.Versions.FirstOrDefault(x => x.PublishingStatusId == publishedId), o => o);
            }
            else if (entity != null && entity.Id.IsAssigned())
            {
                var organization = new OrganizationVersioned {
                    UnificRootId = entity.Id
                };
                definition.AddPartial(i => organization, o => o);
            }
            else
            {
                definition.AddPartial(i => (OrganizationVersioned)null, o => o);
            }

            return(definition.GetFinal());
        }
Exemple #9
0
        private void CheckTranslation(VmOrganizationModel source, VmOrganizationStep1 step1, OrganizationVersioned target)
        {
            target.Id.Should().NotBe(Guid.Empty);

            var names = conversion.GetValidTextsSkipEmpty(step1.OrganizationName, step1.OrganizationAlternateName);

            target.OrganizationNames.Count.Should().Be(Math.Max(names.Count, 1), "OrganizationNames");

            var descriptions = conversion.GetValidTexts(step1.Description);

            target.OrganizationDescriptions.Count.Should().Be(descriptions.Count, "OrganizationDescriptions");

            if (step1.ParentId.HasValue)
            {
                target.ParentId.Should().NotBeEmpty();
                target.ParentId.Should().Be(step1.ParentId.Value);
            }

            if (step1.Municipality?.Id != null)
            {
                target.MunicipalityId.Should().NotBeEmpty();
                target.MunicipalityId.Should().Be(step1.Municipality?.Id);
            }

            if (step1.OrganizationTypeId.HasValue)
            {
                target.TypeId.Should().NotBeEmpty();
                target.TypeId.Should().Be(step1.OrganizationTypeId.Value);
            }

            if (step1.ShowContacts)
            {
                target.OrganizationEmails.Count.Should().Be(step1.Emails.Count, "Emails");
                target.OrganizationPhones.Count.Should().Be(step1.PhoneNumbers.Count, "Phone");
                target.OrganizationWebAddress.Count.Should().Be(step1.WebPages.Count, "Web pages");

                if (step1.ShowPostalAddress || step1.ShowVisitingAddress)
                {
                    target.OrganizationAddresses.Count.Should().Be(step1.PostalAddresses.Count + step1.VisitingAddresses.Count, "Adresses");
                }
            }
        }
        public void ImportDataFromJSON()
        {
            var importedOrganizations = JsonConvert.DeserializeObject <List <SourceOrganizationEntity> >(File.ReadAllText(CreateOrganizationsJsonTask.OrganizationsGeneratedFile), new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            });
            string langCode = LanguageCode.fi.ToString();

            var nameTypeName = NameTypeEnum.Name.ToString();

            using (var serviceScope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var scopedCtxMgr = serviceScope.ServiceProvider.GetService <IContextManager>();

                scopedCtxMgr.ExecuteWriter(unitOfWork =>
                {
                    var defaultLanguage = unitOfWork.CreateRepository <ILanguageRepository>().All().Where(x => x.Code == langCode).First();
                    var defaultNameType = unitOfWork.CreateRepository <INameTypeRepository>().All().Where(x => x.Code == nameTypeName).FirstOrDefault();
                    var publushingStatusNamePublished = PublishingStatus.Published.ToString();
                    var defaultAreaInformationType    = AreaInformationTypeEnum.WholeCountry.ToString();

                    var organizationRepository                = unitOfWork.CreateRepository <IOrganizationVersionedRepository>();
                    var businessRepository                    = unitOfWork.CreateRepository <IBusinessRepository>();
                    var organizationTypeRepository            = unitOfWork.CreateRepository <IOrganizationTypeRepository>();
                    var organizationNameRepository            = unitOfWork.CreateRepository <IOrganizationNameRepository>();
                    var organizationDisplayNameTypeRepository = unitOfWork.CreateRepository <IOrganizationDisplayNameTypeRepository>();
                    var publishingStatusTypeRepository        = unitOfWork.CreateRepository <IPublishingStatusTypeRepository>();
                    var areaInformationTypeRepository         = unitOfWork.CreateRepository <IAreaInformationTypeRepository>();

                    var publishingStatusPublished = publishingStatusTypeRepository.All().Where(x => x.Code == publushingStatusNamePublished).FirstOrDefault();
                    var areaInformationType       = areaInformationTypeRepository.All().Where(x => x.Code == defaultAreaInformationType).FirstOrDefault();

                    foreach (var importedOrganization in importedOrganizations)
                    {
                        Console.Write("#");

                        // Create Organization and Business
                        var business = new Business()
                        {
                            Id        = Guid.NewGuid(),
                            Created   = DateTime.UtcNow,
                            CreatedBy = CreateOrganizationsJsonTask.DefaultCreatedBy,
                            Name      = importedOrganization.Name,
                            //PublishingStatus = publishingStatusPublished,
                            Code = importedOrganization.BusinessId
                        };

                        var organizationTypeName     = importedOrganization.OrganizationType.Trim().Replace(" ", string.Empty);
                        var organizationTypeNameEnum = GetOrganizationType(organizationTypeName).Value;
                        var organizationType         = organizationTypeRepository.All().Where(x => x.Code == organizationTypeNameEnum.ToString()).FirstOrDefault();

                        var organization = new OrganizationVersioned()
                        {
                            Id               = Guid.NewGuid(),
                            Type             = organizationType,
                            Created          = DateTime.UtcNow,
                            CreatedBy        = CreateOrganizationsJsonTask.DefaultCreatedBy,
                            Business         = business,
                            PublishingStatus = publishingStatusPublished,
                            //DisplayNameType = defaultNameType,
                            AreaInformationType = areaInformationType,
                        };

                        var organizationName = new OrganizationName()
                        {
                            Created               = DateTime.UtcNow,
                            CreatedBy             = CreateOrganizationsJsonTask.DefaultCreatedBy,
                            Localization          = defaultLanguage,
                            Name                  = importedOrganization.Name,
                            OrganizationVersioned = organization,
                            Type                  = defaultNameType
                        };

                        var organizationDisplayNameType = new OrganizationDisplayNameType()
                        {
                            Created               = DateTime.UtcNow,
                            CreatedBy             = CreateOrganizationsJsonTask.DefaultCreatedBy,
                            Localization          = defaultLanguage,
                            OrganizationVersioned = organization,
                            DisplayNameType       = defaultNameType
                        };

                        businessRepository.Add(business);
                        organizationRepository.Add(organization);
                        organizationNameRepository.Add(organizationName);
                        organizationDisplayNameTypeRepository.Add(organizationDisplayNameType);
                    }
                    unitOfWork.Save(SaveMode.NonTrackedDataMigration);
                });
            }
        }
        /// <summary>
        /// Creates organizations and businesses for municipalities.
        /// </summary>
        public void Create()
        {
            // Get start data for OrganizationName and BusinessId
            var resourceManager         = new ResourceManager();
            var municipalitiesStartData = resourceManager.GetDesrializedJsonResource <List <VmJsonMunicipality> >(JsonResources.MunicipalityOrganizations);

            using (var serviceScope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var scopedCtxMgr = serviceScope.ServiceProvider.GetService <IContextManager>();

                var organizationTypeMunicipalityName = OrganizationTypeEnum.Municipality.ToString();
                var defaultPublishingStatusName      = PublishingStatus.Published.ToString();
                var defaultAreaInformationTypeName   = AreaInformationTypeEnum.WholeCountry.ToString();
                var nameTypeName = NameTypeEnum.Name.ToString();

                scopedCtxMgr.ExecuteWriter(unitOfWork =>
                {
                    var municipalityRepository                = unitOfWork.CreateRepository <IMunicipalityRepository>();
                    var organizationRepository                = unitOfWork.CreateRepository <IOrganizationVersionedRepository>();
                    var organizationTypeRepository            = unitOfWork.CreateRepository <IOrganizationTypeRepository>();
                    var publishingStatusTypeRepository        = unitOfWork.CreateRepository <IPublishingStatusTypeRepository>();
                    var businessRepository                    = unitOfWork.CreateRepository <IBusinessRepository>();
                    var nameTypeRepository                    = unitOfWork.CreateRepository <INameTypeRepository>();
                    var areaInformationTypeRepository         = unitOfWork.CreateRepository <IAreaInformationTypeRepository>();
                    var organizationTypeId                    = organizationTypeRepository.All().Where(x => x.Code == organizationTypeMunicipalityName).Select(x => x.Id).FirstOrDefault();
                    var organizationNameRepository            = unitOfWork.CreateRepository <IOrganizationNameRepository>();
                    var organizationDisplayNameTypeRepository = unitOfWork.CreateRepository <IOrganizationDisplayNameTypeRepository>();
                    var defaultPublishingStatusType           = publishingStatusTypeRepository.All().FirstOrDefault(x => x.Code == defaultPublishingStatusName);
                    var nameType                     = nameTypeRepository.All().First(x => x.Code == nameTypeName).Id;
                    var languageRepository           = unitOfWork.CreateRepository <ILanguageRepository>();
                    var languages                    = languageRepository.All().ToList(); // no another language versions needed?
                    var languageId                   = languages.First(i => i.Code.ToLower() == LanguageCode.fi.ToString().ToLower()).Id;
                    var defaultAreaInformationTypeId = areaInformationTypeRepository.All().Where(x => x.Code == defaultAreaInformationTypeName).Select(x => x.Id).FirstOrDefault();

                    // Read all municipalities
                    // exclude Helsinki (091) and Mikkeli (491) from results
                    var municipalitiesTemp = unitOfWork.ApplyIncludes(municipalityRepository.All(), i => i.Include(j => j.MunicipalityNames));
                    var municipalities     = municipalitiesTemp.Where(x => x.Code != "491" && x.Code != "091").ToList();

                    foreach (var municipality in municipalities)
                    {
                        Console.Write("#");

                        // Check if the Organization (type == municipality) exists
                        if (!organizationRepository.All().Any(o => o.Municipality.Id == municipality.Id && o.TypeId == organizationTypeId))
                        {
                            var organizationStartData = municipalitiesStartData.FirstOrDefault(s => s.MunicipalityCode == municipality.Code);
                            if (string.IsNullOrEmpty(organizationStartData?.OrganizationName) || string.IsNullOrEmpty(organizationStartData?.BusinessId))
                            {
                                Console.WriteLine($"Municipality '{municipality.Code}' has missing data, creating of Organization skipped!");
                                continue;
                            }
                            var municipalityName = municipality.MunicipalityNames.FirstOrDefault(x => x.LocalizationId == languageId)?.Name;

                            if (!string.IsNullOrEmpty(municipalityName))
                            {
                                // Create Organization and Business
                                var business = new Business()
                                {
                                    Id        = Guid.NewGuid(),
                                    Created   = DateTime.UtcNow,
                                    CreatedBy = CreateMunicipalityOrganizationsTask.DefaultCreatedBy,
                                    Name      = municipalityName,
                                    //Description = municipality.Description,
                                    //PublishingStatus = defaultPublishingStatusType,
                                    Code = organizationStartData.BusinessId
                                };
                                businessRepository.Add(business);
                            }
                            else
                            {
                                Console.WriteLine($"Municipality '{municipality.Code}' has no name in language FI, creating of Organization Business skipped!");
                            }
                            var organization = new OrganizationVersioned()
                            {
                                Id                    = Guid.NewGuid(),
                                Municipality          = municipality,
                                TypeId                = organizationTypeId,
                                AreaInformationTypeId = defaultAreaInformationTypeId,
                                Created               = DateTime.UtcNow,
                                CreatedBy             = CreateMunicipalityOrganizationsTask.DefaultCreatedBy,
                                //Business = business,
                                PublishingStatus = defaultPublishingStatusType,
                                //DisplayNameTypeId = nameType,
                                UnificRoot = new Organization()
                                {
                                    Id = Guid.NewGuid()
                                }
                            };

                            var organizationName = new OrganizationName()
                            {
                                Created               = DateTime.UtcNow,
                                CreatedBy             = CreateMunicipalityOrganizationsTask.DefaultCreatedBy,
                                LocalizationId        = languageId,
                                Name                  = organizationStartData.OrganizationName,
                                OrganizationVersioned = organization,
                                TypeId                = nameType
                            };

                            var organizationDisplayNameType = new OrganizationDisplayNameType()
                            {
                                Created               = DateTime.UtcNow,
                                CreatedBy             = CreateMunicipalityOrganizationsTask.DefaultCreatedBy,
                                LocalizationId        = languageId,
                                OrganizationVersioned = organization,
                                DisplayNameTypeId     = nameType
                            };

                            organizationDisplayNameTypeRepository.Add(organizationDisplayNameType);
                            organizationNameRepository.Add(organizationName);
                            organizationRepository.Add(organization);
                        }
                    }
                    unitOfWork.Save(SaveMode.NonTrackedDataMigration);
                });
            }
        }
        public override VmOpenApiOrganizationVersionBase TranslateEntityToVm(OrganizationVersioned entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var definitions = CreateBaseEntityVmDefinitions(entity)
                              // We have to use unique root id as id!
                              .AddSimple(i => i.UnificRootId, o => o.Id)
                              .AddNavigation(i => i.Municipality, o => o.Municipality)
                              .AddCollection(i => i.OrganizationDescriptions, o => o.OrganizationDescriptions)
                              .AddCollection(i => i.OrganizationEmails.Select(e => e.Email), o => o.EmailAddresses)
                              .AddCollection(i => i.OrganizationPhones, o => o.PhoneNumbers)
                              .AddCollection(i => i.OrganizationAddresses.OrderBy(x => x.CharacterId).ThenBy(x => x.Address.OrderNumber).ThenBy(x => x.Address.Modified), o => o.Addresses)
                              .AddCollection(i => i.OrganizationEInvoicings, o => o.ElectronicInvoicings)
                              .AddCollection(i => i.UnificRoot?.OrganizationServices, o => o.Services)
                              .AddCollection(i => i.UnificRoot?.OrganizationServicesVersioned, o => o.ResponsibleOrganizationServices)
                              .AddCollection(i => i.UnificRoot?.ServiceProducerOrganizations, o => o.ProducerOrganizationServices)
                              .AddSimple(i => i.ParentId, o => o.ParentOrganization)
                              .AddSimple(i => i.Modified, o => o.Modified)
                              .AddCollection(i => i.UnificRoot?.Children, o => o.SubOrganizations);

            if (entity.OrganizationAreaMunicipalities?.Count > 0)
            {
                definitions.AddCollection(i => i.OrganizationAreaMunicipalities.Select(a => a.Municipality), o => o.AreaMunicipalities);
            }
            else
            {
                if (entity.OrganizationAreas?.Count > 0)
                {
                    var areaTypeId = entity.OrganizationAreas.Select(i => i.Area.AreaTypeId).First();
                    var areaType   = typesCache.GetByValue <AreaType>(areaTypeId);
                    definitions.AddCollection(i => i.OrganizationAreas.Select(a => a.Area), o => o.Areas);
                }
            }

            var vm = definitions.GetFinal();

            if (vm.AreaMunicipalities?.Count > 0)
            {
                if (vm.Areas == null)
                {
                    vm.Areas = new List <VmOpenApiArea>();
                }
                vm.Areas.Add(new VmOpenApiArea {
                    Type = AreaTypeEnum.Municipality.ToString(), Municipalities = vm.AreaMunicipalities
                });
            }

            // Map main responsible organizations and producers
            if (vm.ResponsibleOrganizationServices?.Count > 0 || vm.ProducerOrganizationServices?.Count > 0)
            {
                var responsible = "Responsible";
                if (vm.Services == null)
                {
                    vm.Services = new List <V5VmOpenApiOrganizationService>();
                }
                vm.ResponsibleOrganizationServices.ForEach(service =>
                {
                    // Check if there already exists the main responsible organization within OtherResponsible organizations
                    var otherResponsible = vm.Services.Where(s => s.Service.Id == service.Id && s.RoleType == "OtherResponsible").FirstOrDefault();
                    if (otherResponsible != null)
                    {
                        otherResponsible.RoleType = responsible;
                    }
                    else
                    {
                        vm.Services.Add(new V5VmOpenApiOrganizationService()
                        {
                            RoleType              = responsible,
                            OrganizationId        = vm.Id.ToString(),
                            Service               = service,
                            AdditionalInformation = new List <VmOpenApiLanguageItem>(),
                            WebPages              = new List <V4VmOpenApiWebPage>()
                        });
                    }
                });
                vm.ProducerOrganizationServices.ForEach(service => vm.Services.Add(service));
            }

            return(vm);
        }
Exemple #13
0
 protected ITranslationDefinitions <OrganizationVersioned, TVmOpenApiOrganization> CreateBaseEntityVmDefinitions(OrganizationVersioned entity)
 {
     return(CreateEntityViewModelDefinition <TVmOpenApiOrganization>(entity)
            .AddNavigation(i => i.Oid, o => o.Oid)
            .AddNavigation(i => i.Business?.Code, o => o.BusinessCode)
            .AddNavigation(i => i.Business?.Name, o => o.BusinessName)
            .AddNavigation(i => i.TypeId.HasValue ? typesCache.GetByValue <OrganizationType>(i.TypeId.Value) : null, o => o.OrganizationType)
            .AddCollection(i => i.OrganizationNames, o => o.OrganizationNames)
            .AddCollection(i => i.OrganizationWebAddress, o => o.WebPages)
            .AddNavigation(i => typesCache.GetByValue <PublishingStatusType>(i.PublishingStatusId), o => o.PublishingStatus)
            .AddCollection(i => i.OrganizationDisplayNameTypes, o => o.DisplayNameType)
            .AddCollection(i => i.LanguageAvailabilities.Select(l => languageCache.GetByValue(l.LanguageId)).ToList(), o => o.AvailableLanguages)
            .AddNavigation(i => typesCache.GetByValue <AreaInformationType>(i.AreaInformationTypeId), o => o.AreaType));
 }
Exemple #14
0
 public override TVmOpenApiOrganization TranslateEntityToVm(OrganizationVersioned entity)
 {
     return(CreateBaseEntityVmDefinitions(entity).GetFinal());
 }
 private bool GoDeep(ref Dictionary <Guid, List <OrganizationVersioned> > data, OrganizationVersioned orgVersioned, OrganizationVersioned origin, ref Dictionary <Guid, Guid> helpResult, bool childGoing = false)
 {
     if (orgVersioned.UnificRootId == orgVersioned.ParentId)
     {
         return(true);
     }
     if (!childGoing)
     {
         if (helpResult.Keys.Contains(orgVersioned.UnificRootId))
         {
             var item = helpResult[orgVersioned.UnificRootId];
             if (origin != null && item != origin.UnificRootId)
             {
                 return(true);
             }
         }
         else
         {
             helpResult.Add(orgVersioned.UnificRootId, origin?.UnificRootId ?? Guid.Empty);
         }
     }
     if (orgVersioned.ParentId != null)
     {
         var  topChildrens = data[orgVersioned.ParentId.Value];
         var  toCheckChild = topChildrens.First();
         bool isBad        = GoDeep(ref data, toCheckChild, orgVersioned, ref helpResult);
         if (isBad)
         {
             return(true);
         }
     }
     if (!childGoing)
     {
         var sameChildren = data[orgVersioned.UnificRootId];
         foreach (var nodeChild in sameChildren)
         {
             bool isBad = GoDeep(ref data, nodeChild, orgVersioned, ref helpResult, true);
             if (isBad)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #16
0
 public override IVmOpenApiOrganizationInVersionBase TranslateEntityToVm(OrganizationVersioned entity)
 {
     throw new NotImplementedException();
 }