Пример #1
0
 private void ValidateAreas(ModelStateDictionary modelState)
 {
     if (Model.SubAreaType == AreaTypeEnum.Municipality.ToString())
     {
         municipalityList = new MunicipalityCodeListValidator(Model.Areas, codeService, "Areas");
         municipalityList.Validate(modelState);
     }
     else
     {
         areas = new AreaListValidator(Model.Areas, Model.SubAreaType, codeService);
         areas.Validate(modelState);
     }
 }
Пример #2
0
        /// <summary>
        /// Validates area code list.
        /// </summary>
        /// <returns></returns>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (Model == null)
            {
                return;
            }

            AreaInformationTypeEnum?serviceAreaType = null;

            if (!type.IsNullOrEmpty())
            {
                serviceAreaType = type.Parse <AreaInformationTypeEnum>();
            }

            switch (serviceAreaType)
            {
            case AreaInformationTypeEnum.WholeCountry:
            case AreaInformationTypeEnum.WholeCountryExceptAlandIslands:
                // No area info accepted if service are type is WholeCountry or WholeCountryExceptAlandIslands
                if (Model.Count > 0)
                {
                    modelState.AddModelError("Areas", $"No Areas accepted when AreaType has value {type}.");
                }
                break;

            case AreaInformationTypeEnum.AreaType:
            default:
                var i = 0;
                Model.ForEach(area =>
                {
                    if (area.Type == AreaTypeEnum.Municipality.ToString())
                    {
                        municipalities = new MunicipalityCodeListValidator(area.AreaCodes, codeService, $"{ PropertyName }[{ i++ }].AreaCodes");
                        municipalities.Validate(modelState);
                    }
                    else
                    {
                        areas = new AreaListValidator(area.AreaCodes, area.Type, codeService, $"{ PropertyName }[{ i++ }].AreaCodes");
                        areas.Validate(modelState);
                    }
                });
                break;
            }
        }