public CreateRoleLocalizationRequestValidator( IRoleRepository roleRepository, IRoleLocalizationRepository localizationRepository) { RuleFor(x => x.Locale) .NotEmpty() .Length(2); RuleFor(x => x.Name) .NotEmpty() .MaximumLength(100); When(x => x.Name != null && x.Locale != null, () => { RuleFor(x => x) .MustAsync(async(x, _) => !await localizationRepository.DoesNameExistAsync(x.Locale, x.Name)) .WithMessage("Role name should be unique."); }); When(x => x.RoleId.HasValue, () => { RuleFor(x => x) .MustAsync(async(x, _) => await roleRepository.DoesRoleExistAsync(x.RoleId.Value)) .WithMessage("Role must exist.") .MustAsync(async(x, _) => !await localizationRepository.DoesLocaleExistAsync(x.RoleId.Value, x.Locale)) .WithMessage("Role must have only one localization per locale."); }); }
public EditRoleLocalizationCommand( IAccessValidator accessValidator, IResponseCreator responseCreator, IRoleLocalizationRepository roleLocalizationRepository, IPatchDbRoleLocalizationMapper roleLocalizationMapper, IEditRoleLocalizationRequestValidator validator) { _accessValidator = accessValidator; _responseCreator = responseCreator; _roleLocalizationRepository = roleLocalizationRepository; _roleLocalizationMapper = roleLocalizationMapper; _validator = validator; }
public CreateRoleLocalizationCommand( IAccessValidator accessValidator, IResponseCreator responseCreator, IRoleLocalizationRepository roleLocalizationRepository, IDbRoleLocalizationMapper roleLocalizationMapper, ICreateRoleLocalizationRequestValidator requestValidator, IHttpContextAccessor httpContextAccessor) { _accessValidator = accessValidator; _responseCreator = responseCreator; _roleLocalizationRepository = roleLocalizationRepository; _roleLocalizationMapper = roleLocalizationMapper; _requestValidator = requestValidator; _httpContextAccessor = httpContextAccessor; }