Пример #1
0
        /// <summary>
        /// Ctor - service collection validator
        /// </summary>
        /// <param name="model">Service model</param>
        /// <param name="commonService">Common service</param>
        /// <param name="serviceService">Service service</param>
        /// <param name="newLanguages">Languages that should be validated within lists</param>
        /// <param name="userOrganizations">List of user organizations</param>
        public ServiceCollectionValidator(
            IVmOpenApiServiceCollectionInVersionBase model,
            ICommonService commonService,
            IServiceService serviceService,
            IList <string> newLanguages,
            IList <Guid> userOrganizations
            ) : base(model, "ServiceCollection")
        {
            if (model == null)
            {
                throw new ArgumentNullException(PropertyName, $"{PropertyName} must be defined.");
            }

            names            = new LanguageItemListValidator(model.ServiceCollectionNames, "ServiceCollectionNames", newLanguages);
            status           = new PublishingStatusValidator(model.PublishingStatus, model.CurrentPublishingStatus);
            mainOrganization = new UserOrganizationIdValidator(model.MainResponsibleOrganization, commonService, userOrganizations, "MainResponsibleOrganization");

            // Validate service ids
            if (model.ServiceCollectionServices != null)
            {
                services = new ServiceIdListValidator(model.ServiceCollectionServices.ToList(), serviceService, "Services");
            }

            this.newLanguages = newLanguages;
        }
Пример #2
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");
        }
        /// <summary>
        /// Validates service channels
        /// </summary>
        /// <param name="modelState"></param>
        public override void Validate(ModelStateDictionary modelState)
        {
            if (Model == null)
            {
                return;
            }

            Guid?channelId = Model.Count > 0 ? Model.First().ChannelGuid : (Guid?)null;

            if (!channelId.HasValue)
            {
                return;
            }

            var channelValidator = new ServiceChannelIdValidator(channelId.Value, channelService, UserRoleEnum.Eeva, "ServiceChannelId"); // this is always asti connection so we won't check the channel for visibility by setting user role as Eeva!

            channelValidator.Validate(modelState);
            if (!modelState.IsValid)
            {
                return;
            }

            var channel = channelValidator.ServiceChannel;

            if (channel.ServiceChannelType != ServiceChannelTypeEnum.ServiceLocation.ToString() && Model.Any(c => c.ServiceHours?.Count > 0 || c.ContactDetails != null))
            {
                modelState.AddModelError(PropertyName, string.Format(CoreMessages.OpenApi.AdditionalInfoForConnection, channel.Id, channel.ServiceChannelType));
            }
            else
            {
                // Validate service ids
                var serviceIds = Model.Select(c => c.ServiceGuid).ToList();
                ServiceIdListValidator services = new ServiceIdListValidator(serviceIds, serviceService, "ServiceRelations", "ServiceId");
                services.Validate(modelState);
            }
        }