Exemple #1
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);
        }
Exemple #2
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);
        }