/// <summary> /// Validates service channel id list. /// </summary> /// <returns></returns> public override void Validate(ModelStateDictionary modelState) { if (Model == null) { return; } var i = 0; Model.ForEach(id => { var channelId = new ServiceChannelIdValidator(id, channelService, userRole, $"[{ i++ }].{PropertyName}"); channelId.Validate(modelState); }); }
/// <summary> /// Validates channel id. /// </summary> /// <returns></returns> public override void Validate(ModelStateDictionary modelState) { if (Model == null) { return; } channelValidator.Validate(modelState); if (!modelState.IsValid) { return; } var channel = channelValidator.ServiceChannel; // additional connection information (service hours & contact information) are only allowed for service location channel. PTV-2475 if (channel != null && channel.ServiceChannelType != ServiceChannelTypeEnum.ServiceLocation.ToString() && (Model.ServiceHours?.Count > 0 || Model.ContactDetails != null)) { modelState.AddModelError(PropertyName, string.Format(CoreMessages.OpenApi.AdditionalInfoForConnection, channel.Id, channel.ServiceChannelType)); return; } }
/// <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); } }