/// <summary>
        /// Validates general description model.
        /// </summary>
        public override void Validate(ModelStateDictionary modelState)
        {
            names.Validate(modelState);
            if (Model.Descriptions?.Where(d => d.Type == DescriptionTypeEnum.Description.ToString()).FirstOrDefault() == null &&
                Model.Descriptions?.Where(d => d.Type == DescriptionTypeEnum.BackgroundDescription.ToString()).FirstOrDefault() == null && newLanguages?.Count > 0)
            {
                modelState.AddModelError("Descriptions", string.Format(CoreMessages.OpenApi.RequiredValueWithLanguageAndTypeNotFound,
                                                                       $"{ DescriptionTypeEnum.Description.ToString()} or { DescriptionTypeEnum.BackgroundDescription.ToString()}", newLanguages.First()));

                descriptions = new LocalizedListValidator(Model.Descriptions, "Descriptions", newLanguages,
                                                          new List <string>()
                {
                    DescriptionTypeEnum.ShortDescription.ToString()
                });
            }
            else
            {
                var descriptionType = Model.Descriptions?.Where(d => d.Type != DescriptionTypeEnum.ShortDescription.ToString()).Select(d => d.Type).FirstOrDefault();
                descriptions = new LocalizedListValidator(Model.Descriptions, "Descriptions", newLanguages,
                                                          new List <string>()
                {
                    DescriptionTypeEnum.ShortDescription.ToString(), descriptionType
                });
            }
            descriptions.Validate(modelState);
            languages.Validate(modelState);
            serviceClasses.Validate(modelState);
            ontologyTerms.Validate(modelState);
            targetGroups.Validate(modelState);
            lifeEvents.Validate(modelState);
            industrialClasses.Validate(modelState);
            status.Validate(modelState);
        }
Beispiel #2
0
        /// <summary>
        /// Checks if electronic channel model is valid or not.
        /// </summary>
        /// <param name="modelState"></param>
        public override void Validate(ModelStateDictionary modelState)
        {
            // Validate names against newly added languages (required languages)
            var names = new LanguageItemListValidator(Model.ServiceChannelNames, "ServiceChannelNames", requiredLanguages);

            names.Validate(modelState);
            // Validate descriptions against newly added languages (required languages), all the available languages does not need to be validated.
            var descriptions = new LocalizedListValidator(Model.ServiceChannelDescriptions, "ServiceChannelDescriptions", requiredLanguages,
                                                          new List <string>()
            {
                DescriptionTypeEnum.ShortDescription.ToString(), DescriptionTypeEnum.Description.ToString()
            });

            descriptions.Validate(modelState);

            hours.Validate(modelState);
            organizationId.Validate(modelState);
            languages.Validate(modelState);
            phones.Validate(modelState);

            // Validate publishing status
            var status = new PublishingStatusValidator(Model.PublishingStatus, currentPublishingStatus);

            status.Validate(modelState);

            areas.Validate(modelState);
            services.Validate(modelState);
        }
Beispiel #3
0
        /// <summary>
        /// Validates printable form channel model.
        /// </summary>
        /// <param name="modelState"></param>
        public override void Validate(ModelStateDictionary modelState)
        {
            base.Validate(modelState);

            address.Validate(modelState);

            // Validate required channelUrls property
            var urls = new LocalizedListValidator(Model.ChannelUrls, "ChannelUrls", requiredLanguages: RequiredLanguages, availableLanguages: AvailableLanguages);

            urls.Validate(modelState);
        }
        /// <summary>
        /// Validate organization model.
        /// </summary>
        public override void Validate(ModelStateDictionary modelState)
        {
            OrganizationTypeEnum?organizationType = null;

            if (!Model.OrganizationType.IsNullOrEmpty())
            {
                organizationType = Model.OrganizationType.Parse <OrganizationTypeEnum>();
            }

            name.Validate(modelState);

            // Validate municipality
            if (organizationType != OrganizationTypeEnum.Municipality && !Model.Municipality.IsNullOrEmpty())
            {
                modelState.AddModelError("Municipality", $"No Municipality accepted when OrganizationType has value {Model.OrganizationType}.");
            }
            else
            {
                municipality.Validate(modelState);
            }

            addresses.Validate(modelState);
            organizationId.Validate(modelState);
            oid.Validate(modelState);
            phones.Validate(modelState);
            status.Validate(modelState);

            // Validate organization descriptions: ShortDescription on is mandatory on versions 7+
            if (versionNumber >= 7)
            {
                description.Validate(modelState);
            }

            // Validate area data according to organization type
            switch (organizationType)
            {
            case OrganizationTypeEnum.Municipality:
            case OrganizationTypeEnum.TT1:
            case OrganizationTypeEnum.TT2:
                // No area info accepted if organization type is Municipality, TT1 or TT2 - except default value areaType => WholeCountry!
                if (!Model.AreaType.IsNullOrEmpty() && Model.AreaType != AreaInformationTypeEnum.WholeCountry.ToString())
                {
                    modelState.AddModelError("AreaType", $"Value '{ Model.AreaType}' not accepted when OrganizationType has value {Model.OrganizationType}.");
                }
                if (!Model.SubAreaType.IsNullOrEmpty())
                {
                    modelState.AddModelError("SubAreaType", $"No SubAreaType accepted when OrganizationType has value {Model.OrganizationType}.");
                }
                if (Model.Areas?.Count > 0)
                {
                    modelState.AddModelError("Areas", $"No Areas accepted when OrganizationType has value {Model.OrganizationType}.");
                }
                break;

            case OrganizationTypeEnum.RegionalOrganization:
                // Only AreaType is accepted if organization type is RegionalOrganization.
                if (Model.AreaType != AreaInformationTypeEnum.AreaType.ToString())
                {
                    modelState.AddModelError("AreaType", $"Value {AreaInformationTypeEnum.AreaType.ToString()} required when OrganizationType has value {Model.OrganizationType}.");
                }

                // Validate the area codes
                ValidateAreas(modelState);

                break;

            case null:
                if (!Model.AreaType.IsNullOrEmpty() || !Model.SubAreaType.IsNullOrEmpty() || Model.Areas?.Count > 0)
                {
                    modelState.AddModelError("OrganizationType", $"OrganizationType field is required when AreaType, SubAreaType or Areas has values.");
                }
                break;

            default:
                if (Model.AreaType != AreaInformationTypeEnum.AreaType.ToString() && !Model.SubAreaType.IsNullOrEmpty())
                {
                    modelState.AddModelError("SubAreaType", $"No SubAreaType accepted when AreaType has value {Model.AreaType}.");
                }
                if (Model.AreaType != AreaInformationTypeEnum.AreaType.ToString() && Model.Areas?.Count > 0)
                {
                    modelState.AddModelError("Areas", $"No Areas accepted when AreaType has value {Model.AreaType}.");
                }
                // For State, Organization and Company types we are validating the area codes
                ValidateAreas(modelState);
                break;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Checks if service model is valid or not.
        /// </summary>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (!generalDescriptionAttached)
            {
                // validate names if general description is not set (name is taken from general description if not set).
                names.Validate(modelState);
                // Validate all required descriptions
                descriptions = new LocalizedListValidator(Model.ServiceDescriptions, "ServiceDescriptions", newLanguages,
                                                          new List <string>()
                {
                    DescriptionTypeEnum.ShortDescription.ToString(), DescriptionTypeEnum.Description.ToString()
                });
            }
            else
            {
                // General description was defined.
                var gdId = Model.StatutoryServiceGeneralDescriptionId.ParseToGuid();
                if (gdId.HasValue)
                {
                    var gd = generalDescriptionService.GetGeneralDescriptionVersionBase(gdId.Value, 0);
                    if (gd == null || !gd.Id.HasValue)
                    {
                        modelState.AddModelError("StatutoryServiceGeneralDescriptionId", CoreMessages.OpenApi.RecordNotFound);
                    }
                    else
                    {
                        if (gd.Descriptions == null || gd.Descriptions.Where(d => d.Type == DescriptionTypeEnum.Description.ToString() && d.Value != null && d.Value.Length > 0).FirstOrDefault() == null)
                        {
                            // Description was not defined within GD - service model need to include all required description, so let's validate both ShortDescription and Description
                            descriptions = new LocalizedListValidator(Model.ServiceDescriptions, "ServiceDescriptions", newLanguages,
                                                                      new List <string>()
                            {
                                DescriptionTypeEnum.ShortDescription.ToString(), DescriptionTypeEnum.Description.ToString()
                            });
                        }
                        else
                        {
                            // Validate only ShortDescription for Descriptions. Description is not required if it is defined within GD.
                            descriptions = new LocalizedListValidator(Model.ServiceDescriptions, "ServiceDescriptions", newLanguages,
                                                                      new List <string>()
                            {
                                DescriptionTypeEnum.ShortDescription.ToString()
                            });
                        }
                    }
                }
                else
                {
                    modelState.AddModelError("StatutoryServiceGeneralDescriptionId", CoreMessages.OpenApi.RecordNotFound);
                }
            }

            if (descriptions != null)
            {
                descriptions.Validate(modelState);
            }
            //municipalities.Validate(modelState); // We do not need to validate municipalities anymore - they are mapped into Model.Areas in VmOpenApiServiceInVersionBase
            languages.Validate(modelState);
            serviceClasses.Validate(modelState);
            ontologyTerms.Validate(modelState);
            targetGroups.Validate(modelState);
            lifeEvents.Validate(modelState);
            industrialClasses.Validate(modelState);
            organizations.Validate(modelState);
            status.Validate(modelState);

            // Validate area type, service areas and municipalities
            areas.Validate(modelState);

            channels.Validate(modelState);
            serviceProducers.Validate(modelState);
            mainOrganization.Validate(modelState);
        }