Пример #1
0
        /// <summary>
        /// Checks if municipality code is valid or not.
        /// </summary>
        /// <returns></returns>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (string.IsNullOrEmpty(Model))
            {
                return;
            }
            var postalInfo = codeService.GetPostalCodeByCode(Model);

            if (string.IsNullOrEmpty(postalInfo))
            {
                modelState.AddModelError(PropertyName, string.Format(CoreMessages.OpenApi.CodeNotFound, Model));
            }
        }
Пример #2
0
        private bool PostalCodeExists(IList <V5VmOpenApiAddressWithTypeIn> addresses)
        {
            var errorMsg = new StringBuilder();

            addresses.ForEach(a =>
            {
                var postalInfo = codeService.GetPostalCodeByCode(a.PostalCode);
                if (postalInfo == null)
                {
                    errorMsg.AppendLine($"Postalcode {a.PostalCode} does not exist!");
                }
            });
            if (errorMsg.Length > 0)
            {
                throw new Exception(errorMsg.ToString());
            }

            return(true);
        }