/// <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>
        /// Ctor - service validator
        /// </summary>
        /// <param name="model">Service model</param>
        /// <param name="generalDescriptionService">General description service</param>
        /// <param name="codeService">Code service</param>
        /// <param name="fintoService">Finto item service</param>
        /// <param name="commonService">Common service</param>
        /// <param name="channelService">Channel service</param>
        /// <param name="newLanguages">Languages that should be validated within lists</param>
        /// <param name="userRole">User role</param>
        public ServiceValidator(
            IVmOpenApiServiceInVersionBase model,
            IGeneralDescriptionService generalDescriptionService,
            ICodeService codeService,
            IFintoService fintoService,
            ICommonService commonService,
            IChannelService channelService,
            IList <string> newLanguages,
            UserRoleEnum userRole
            ) : base(model, "Service")
        {
            this.generalDescriptionService = generalDescriptionService;

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

            names = new LocalizedListValidator(model.ServiceNames, "ServiceNames", newLanguages, new List <string>()
            {
                NameTypeEnum.Name.ToString()
            });
            languages         = new LanguageListValidator(model.Languages, codeService);
            serviceClasses    = new ServiceClassListValidator(model.ServiceClasses, fintoService);
            ontologyTerms     = new OntologyTermListValidator(model.OntologyTerms, fintoService);
            targetGroups      = new TargetGroupListValidator(model.TargetGroups, fintoService);
            lifeEvents        = new LifeEventListValidator(model.LifeEvents, fintoService);
            industrialClasses = new IndustrialClassListValidator(model.IndustrialClasses, fintoService);
            organizations     = new OrganizationIdListValidator(model.OtherResponsibleOrganizations?.Select(o => o.ToString()).ToList(), commonService, "OtherResponsibleOrganizations");
            status            = new PublishingStatusValidator(model.PublishingStatus, model.CurrentPublishingStatus);
            areas             = new AreaAndTypeValidator(model.Areas, model.AreaType, codeService);
            var channelList = model.ServiceServiceChannels?.Count > 0 ? model.ServiceServiceChannels.Select(i => i.ChannelGuid).ToList() : new List <Guid>();

            channels = new ServiceChannelIdListValidator(channelList, channelService, userRole, "ServiceChannels");

            var availableOrganizations = new List <Guid>();

            if (!model.MainResponsibleOrganization.IsNullOrEmpty())
            {
                availableOrganizations.Add(model.MainResponsibleOrganization.ParseToGuidWithExeption());
            }
            if (model.OtherResponsibleOrganizations?.Count > 0)
            {
                availableOrganizations.AddRange(model.OtherResponsibleOrganizations);
            }
            serviceProducers = new ServiceProducerListValidator(model.ServiceProducers, availableOrganizations, commonService);

            mainOrganization = new OrganizationIdValidator(model.MainResponsibleOrganization, commonService, "MainResponsibleOrganization");

            generalDescriptionAttached = !string.IsNullOrEmpty(model.StatutoryServiceGeneralDescriptionId);
            this.newLanguages          = newLanguages;
        }
        /// <summary>
        /// Checks if organization id list is valid or not.
        /// </summary>
        /// <returns></returns>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (Model == null)
            {
                return;
            }

            var i = 0;

            Model.ForEach(id =>
            {
                var organizationId = new OrganizationIdValidator(id, commonService, $"{PropertyName}[{ i++ }].OrganizationId");
                organizationId.Validate(modelState);
            });
        }
示例#4
0
        /// <summary>
        /// Ctor - channel validator
        /// </summary>
        /// <param name="model"></param>
        /// <param name="propertyName">Property name</param>
        /// <param name="commonService">Common service</param>
        /// <param name="codeService">Code service</param>
        /// <param name="serviceService">Service service</param>
        public ServiceChannelValidator(TModel model, string propertyName, ICommonService commonService, ICodeService codeService, IServiceService serviceService)
            : base(model, propertyName)
        {
            if (model == null)
            {
                throw new ArgumentNullException(PropertyName, $"{PropertyName} must be defined.");
            }

            this.codeService   = codeService;
            requiredLanguages  = new List <string>();
            availableLanguages = new List <string>();

            hours          = new ServiceHourListValidator <V4VmOpenApiServiceHour>(model.ServiceHours);
            organizationId = new OrganizationIdValidator(model.OrganizationId, commonService);
            languages      = new LanguageListValidator(model.Languages, codeService);
            phones         = new PhoneNumberListValidator <V4VmOpenApiPhone>(model.SupportPhones, codeService); // Support phone property is not required so no need to check language items (required/available languages)
            areas          = new AreaAndTypeValidator(model.Areas, model.AreaType, codeService);
            services       = new ServiceIdListValidator(model.ServiceChannelServices.ToList(), serviceService, "Services");
        }