private void SetStep1Translation(ITranslationDefinitions <VmService, ServiceVersioned> definition, VmService service) { var model = service.Step1Form; var order = 1; model.Laws?.ForEach(i => { i.OrderNumber = order++; i.OwnerReferenceId = model.Id; }); var serviceTypeId = model.GeneralDescription?.UnificRootId == null ? model.ServiceTypeId : model.GeneralDescription.TypeId; var names = new List <VmName>() { new VmName { Name = model.ServiceName, TypeId = typesCache.Get <NameType>(NameTypeEnum.Name.ToString()), OwnerReferenceId = service.Id } }; if (!string.IsNullOrEmpty(model.AlternateServiceName)) { names.Add(new VmName { Name = model.AlternateServiceName, TypeId = typesCache.Get <NameType>(NameTypeEnum.AlternateName.ToString()), OwnerReferenceId = service.Id }); } var descriptions = new List <VmDescription>() { new VmDescription { Description = model.ShortDescriptions, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ShortDescription.ToString()), OwnerReferenceId = service.Id }, new VmDescription { Description = model.Description, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.Description.ToString()), OwnerReferenceId = service.Id }, new VmDescription { Description = model.UserInstruction, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ServiceUserInstruction.ToString()), OwnerReferenceId = service.Id }, new VmDescription { Description = model.AdditionalInformation, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ChargeTypeAdditionalInfo.ToString()), OwnerReferenceId = service.Id } }; if (!typesCache.Compare <ServiceType>(serviceTypeId, ServiceTypeEnum.Service.ToString())) { descriptions.Add(new VmDescription { Description = model.AdditionalInformationDeadLine, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.DeadLineAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); descriptions.Add(new VmDescription { Description = model.AdditionalInformationProcessingTime, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ProcessingTimeAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); // descriptions.Add(new VmDescription { Description = model.AdditionalInformationTasks, TypeId = typesCache.Get<DescriptionType>(DescriptionTypeEnum.TasksAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); descriptions.Add(new VmDescription { Description = model.AdditionalInformationValidityTime, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ValidityTimeAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); } else { if (service.Id.IsAssigned()) { descriptions.Add(new VmDescription { TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.DeadLineAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); descriptions.Add(new VmDescription { TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ProcessingTimeAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); //descriptions.Add(new VmDescription { TypeId = typesCache.Get<DescriptionType>(DescriptionTypeEnum.TasksAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); descriptions.Add(new VmDescription { TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.ValidityTimeAdditionalInfo.ToString()), OwnerReferenceId = service.Id }); } } if (typesCache.Compare <AreaInformationType>(service.Step1Form.AreaInformationTypeId, AreaInformationTypeEnum.AreaType.ToString())) { var areas = service.Step1Form.BusinessRegions.Union(service.Step1Form.HospitalRegions).Union(service.Step1Form.Provinces); definition.AddCollectionWithRemove(i => areas.Select(x => new VmListItem { Id = x, OwnerReferenceId = service.Id }), o => o.Areas, r => true); definition.AddCollectionWithRemove(i => i.Step1Form.Municipalities.Select(x => new VmListItem { Id = x, OwnerReferenceId = service.Id }), o => o.AreaMunicipalities, r => true); } else { //Remove Areas definition.AddCollectionWithRemove(i => new List <VmListItem>() { }, o => o.Areas, r => true); definition.AddCollectionWithRemove(i => new List <VmListItem>() { }, o => o.AreaMunicipalities, r => true); } var defaultAreaInformationTypeId = typesCache.Get <AreaInformationType>(AreaInformationTypeEnum.WholeCountry.ToString()); var generalDescriptionUnificRootIdIsAssigned = model.GeneralDescription != null?model.GeneralDescription.UnificRootId.IsAssigned() : false; var languageCount = 0; definition .AddSimple(i => generalDescriptionUnificRootIdIsAssigned ? model.GeneralDescription.UnificRootId : (Guid?)null, o => o.StatutoryServiceGeneralDescriptionId) .AddSimple(i => generalDescriptionUnificRootIdIsAssigned ? null : i.Step1Form.ServiceTypeId, o => o.TypeId) .AddSimple(i => i.Step1Form.ChargeType, o => o.ChargeTypeId) .AddSimple(i => i.Step1Form.AreaInformationTypeId.IsAssigned() ? i.Step1Form.AreaInformationTypeId : defaultAreaInformationTypeId, output => output.AreaInformationTypeId) .AddCollectionWithKeep(i => names, o => o.ServiceNames, TranslationPolicy.FetchData, x => x.LocalizationId != RequestLanguageId) .AddCollection(i => descriptions, o => o.ServiceDescriptions) .AddCollection( i => new List <VmServiceRequirement> { new VmServiceRequirement { Requirement = model.ServiceUsage, Id = service.Id } }, o => o.ServiceRequirements) .AddCollectionWithRemove(i => i.Step1Form.Languages.Select(x => new VmListItem { Id = x, OrderNumber = languageCount++, OwnerReferenceId = i.Id }), o => o.ServiceLanguages, r => true) //.AddCollection(i => i.Step1Form.Laws.Where(x => !string.IsNullOrEmpty(x.UrlAddress.TryGet(RequestLanguageCode.ToString()))), output => output.ServiceLaws, false) .AddCollectionWithKeep(i => i.Step1Form.Laws /*.Where(x => !string.IsNullOrEmpty(x.UrlAddress.TryGet(RequestLanguageCode.ToString())))*/, output => output.ServiceLaws, c => { c.Check(h => h.Law).Check(h => h.Names).Any(); c.Check(h => h.Law).Check(h => h.WebPages).Any(); c.Check(h => h.Law).Check(h => h.WebPages).Check(h => h.WebPage).Check(h => h.LocalizationId).Not(RequestLanguageId); }) .AddCollectionWithRemove(i => i.Step1Form.Organizers.Select(x => new VmTreeItem { Id = x, OwnerReferenceId = i.Id }), o => o.OrganizationServices, r => true) .AddSimple(i => i.Step1Form.FundingTypeId, o => o.FundingTypeId) .AddSimple(i => i.Step1Form.OrganizationId, o => o.OrganizationId) .AddCollectionWithKeep(i => i.Step1Form.ServiceVouchers, o => o.ServiceWebPages, c => c.Check(h => h.WebPage).Check(h => h.LocalizationId).Not(RequestLanguageId)); // handle selfProduced serviceProducers if (service.Id.IsAssigned()) { var selfProducedId = typesCache.Get <ProvisionType>(ProvisionTypeEnum.SelfProduced.ToString()); var selfProducedOrganizations = service.Step1Form.ServiceProducers.Where(p => p.ProvisionType == selfProducedId && p.SelfProducers != null).Select(x => { var organizers = service.Step1Form.Organizers; if (service.Step1Form.OrganizationId.IsAssigned()) { organizers.Add(service.Step1Form.OrganizationId); } x.SelfProducers = x.SelfProducers.Where(org => organizers.Contains(org)).ToList(); return(x); }).ToList(); definition.AddCollectionWithKeep(i => selfProducedOrganizations, o => o.ServiceProducers, r => r.ProvisionTypeId != selfProducedId); } }
private void SetStep1Translation(ITranslationDefinitions <VmOrganizationModel, OrganizationVersioned> definition, VmOrganizationModel organization) { var model = organization.Step1Form; var names = new List <VmName>() { new VmName { Name = model.OrganizationName, TypeId = typesCache.Get <NameType>(NameTypeEnum.Name.ToString()), OwnerReferenceId = organization.Id } }; if (!string.IsNullOrEmpty(model.OrganizationAlternateName) || (model.DisplayNameId == typesCache.Get <NameType>(NameTypeEnum.AlternateName.ToString()))) { names.Add(new VmName { Name = model.OrganizationAlternateName, TypeId = typesCache.Get <NameType>(NameTypeEnum.AlternateName.ToString()), OwnerReferenceId = organization.Id }); } var descriptions = new List <VmDescription>() { new VmDescription { Description = model.Description, TypeId = typesCache.Get <DescriptionType>(DescriptionTypeEnum.Description.ToString()), OwnerReferenceId = organization.Id }, }; definition.AddNavigation(i => i.Step1Form.Business, o => o.Business); if (model.OrganizationTypeId.IsAssigned() && typesCache.Compare <AreaInformationType>(model.AreaInformationTypeId, AreaInformationTypeEnum.AreaType.ToString())) { if (typesCache.Compare <OrganizationType>(model.OrganizationTypeId, OrganizationTypeEnum.State.ToString()) || typesCache.Compare <OrganizationType>(model.OrganizationTypeId, OrganizationTypeEnum.Organization.ToString()) || typesCache.Compare <OrganizationType>(model.OrganizationTypeId, OrganizationTypeEnum.Company.ToString()) || typesCache.Compare <OrganizationType>(model.OrganizationTypeId, OrganizationTypeEnum.RegionalOrganization.ToString())) { var areas = model.BusinessRegions.Union(model.HospitalRegions).Union(model.Provinces); definition.AddCollection(i => areas.Select(x => new VmListItem { Id = x, OwnerReferenceId = organization.Id }), o => o.OrganizationAreas); definition.AddCollection(i => i.Step1Form.Municipalities.Select(x => new VmListItem { Id = x, OwnerReferenceId = organization.Id }), o => o.OrganizationAreaMunicipalities); } } else { //Remove Areas definition.AddCollection(i => new List <VmListItem>() { }, o => o.OrganizationAreas); definition.AddCollection(i => new List <VmListItem>() { }, o => o.OrganizationAreaMunicipalities); } var nameType = new VmDispalyNameType { NameTypeId = model.DisplayNameId, OwnerReferenceId = organization.Id }; var order = 1; model.Emails.ForEach(email => email.OrderNumber = order++); order = 1; model.PhoneNumbers.ForEach(phone => phone.OrderNumber = order++); order = 1; model.VisitingAddresses.ForEach(item => item.OrderNumber = order++); order = 1; model.PostalAddresses.ForEach(item => item.OrderNumber = order++); var defaultAreaInformationTypeId = typesCache.Get <AreaInformationType>(AreaInformationTypeEnum.WholeCountry.ToString()); definition .AddSimple(i => i.Step1Form.OrganizationTypeId, o => o.TypeId) .AddSimple(i => i.Step1Form.AreaInformationTypeId.IsAssigned() ? i.Step1Form.AreaInformationTypeId : defaultAreaInformationTypeId, output => output.AreaInformationTypeId) .AddSimple(i => i.Step1Form.ParentId, o => o.ParentId) .AddSimple(i => i.Step1Form.Municipality?.Id, o => o.MunicipalityId) //.AddSimple(i => i.Step1Form.DisplayNameId, o => o.DisplayNameTypeId) .AddNavigation(i => i.Step1Form.OrganizationId, o => o.Oid) .AddLocalizable(i => nameType, o => o.OrganizationDisplayNameTypes) .AddCollectionWithKeep(i => names, o => o.OrganizationNames, TranslationPolicy.FetchData, x => x.LocalizationId != RequestLanguageId) .AddCollectionWithKeep(i => descriptions, o => o.OrganizationDescriptions, TranslationPolicy.FetchData, x => x.LocalizationId != RequestLanguageId); //model.ShowContacts definition .AddCollection(i => i.Step1Form.Emails, o => o.OrganizationEmails) .AddCollection(i => i.Step1Form.PhoneNumbers, o => o.OrganizationPhones) .AddCollection(i => i.Step1Form.WebPages, o => o.OrganizationWebAddress); //model.ShowPostalAddress || model.ShowVisitingAddress) var addresses = new List <VmAddressSimple>(); addresses = model.PostalAddresses.Any() ? addresses.Concat(model.PostalAddresses.Where(x => (x.PostalCode != null && x.StreetType != AddressTypeEnum.Foreign.ToString()) || x.StreetType == AddressTypeEnum.Foreign.ToString())).ToList() : addresses; addresses = model.VisitingAddresses.Any() ? addresses.Concat(model.VisitingAddresses.Where(x => (x.PostalCode != null && x.StreetType != AddressTypeEnum.Foreign.ToString()) || x.StreetType == AddressTypeEnum.Foreign.ToString())).ToList() : addresses; addresses.ForEach(x => x.OwnerReferenceId = organization.Id); definition.AddCollection(i => addresses, o => o.OrganizationAddresses); }