/// <summary>
        /// Ctor - organization validator
        /// </summary>
        /// <param name="model">Organization model</param>
        /// <param name="codeService">Code service</param>
        /// <param name="organizationService">Organization service</param>
        /// <param name="commonService">Common service</param>
        /// <param name="newLanguages">Languages that should be validated within lists</param>
        /// <param name="availableLanguages">The languages that are available in main model and therefore need to be validated.</param>
        /// <param name="isCreateOperation">Indicates if organization is beeing inserted or updated.</param>
        /// <param name="versionNumber">Version number.</param>
        public OrganizationValidator(IVmOpenApiOrganizationInVersionBase model, ICodeService codeService, IOrganizationService organizationService, IList <string> newLanguages, IList <string> availableLanguages, ICommonService commonService, int versionNumber, bool isCreateOperation = false)
            : base(model, "Organization")
        {
            this.codeService = codeService;

            if (model == null)
            {
                throw new ArgumentNullException(PropertyName, $"{PropertyName} must be defined.");
            }

            name = new LocalizedListValidator(model.OrganizationNames, "OrganizationNames", newLanguages, new List <string>()
            {
                NameTypeEnum.Name.ToString()
            });
            municipality   = new MunicipalityCodeValidator(model.Municipality, codeService);
            addresses      = new AddressListValidator <V7VmOpenApiAddressWithForeignIn>(model.Addresses, codeService);
            organizationId = new OrganizationIdValidator(model.ParentOrganizationId, commonService, "ParentOrganizationId");
            oid            = new OidValidator(model.Oid, organizationService, isCreateOperation: isCreateOperation, organizationId: model.Id, sourceId: model.SourceId);
            phones         = new PhoneNumberListValidator <V4VmOpenApiPhone>(model.PhoneNumbers, codeService);
            status         = new PublishingStatusValidator(model.PublishingStatus, model.CurrentPublishingStatus);
            description    = new LocalizedListValidator(model.OrganizationDescriptions, "OrganizationDescriptions", newLanguages, new List <string>()
            {
                DescriptionTypeEnum.ShortDescription.ToString()
            }, availableLanguages);
            this.versionNumber = versionNumber;
        }
示例#2
0
        /// <summary>
        /// Checks if municipality code list is valid or not.
        /// </summary>
        /// <returns></returns>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (Model == null)
            {
                return;
            }

            var i = 0;

            Model.ForEach(code =>
            {
                var municipality = new MunicipalityCodeValidator(code, codeService, $"{PropertyName}[{ i++ }]");
                municipality.Validate(modelState);
            });
        }
示例#3
0
        /// <summary>
        /// Checks if address is valid or not.
        /// </summary>
        /// <param name="modelState"></param>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (Model == null)
            {
                return;
            }

            // Visiting address cannot be post office box
            if (Model.Type == AddressCharacterEnum.Visiting.ToString() && Model.SubType == AddressTypeEnum.PostOfficeBox.ToString())
            {
                modelState.AddModelError(PropertyName, "The field is invalid. 'SubType' cannot have value 'PostOfficeBox' when 'Type' = 'Visiting'.");
                return;
            }

            if (Model.SubType == AddressTypeEnum.PostOfficeBox.ToString())
            {
                if (Model.PostOfficeBoxAddress == null)
                {
                    return;
                }

                // Validate municipality code
                var municipality = new MunicipalityCodeValidator(Model.PostOfficeBoxAddress.Municipality, codeService, $"{PropertyName}.PostOfficeBoxAddress.Municipality");
                municipality.Validate(modelState);

                // Validate postal code
                var postalCode = new PostalCodeValidator(Model.PostOfficeBoxAddress.PostalCode, codeService, $"{PropertyName}.PostOfficeBoxAddress.PostalCode");
                postalCode.Validate(modelState);
            }
            else if (Model.SubType == AddressTypeEnum.Street.ToString() || Model.SubType == AddressConsts.SINGLE)
            {
                if (Model.StreetAddress == null)
                {
                    return;
                }

                // Validate municipality code
                var municipality = new MunicipalityCodeValidator(Model.StreetAddress.Municipality, codeService, $"{PropertyName}.StreetAddress.PostOfficeBoxAddress.Municipality");
                municipality.Validate(modelState);

                // Validate postal code
                var postalCode = new PostalCodeValidator(Model.StreetAddress.PostalCode, codeService, $"{PropertyName}.StreetAddress.PostalCode");
                postalCode.Validate(modelState);
            }
        }