public BookingValidator(IClientsRepository clientsRepository, IRoomsRepository roomsRepository, IBookingsRepository bookingsRepository) { _clientsRepository = clientsRepository; _roomsRepository = roomsRepository; _bookingsRepository = bookingsRepository; RuleFor(booking => booking.ClientId) .Cascade(CascadeMode.Stop) .NotEmpty() .MustAsync(async(clientId, cancellation) => { return(await _clientsRepository.IsClientExistsAsync(clientId)); }) .WithMessage("Client with this id doesn't exists."); RuleFor(booking => booking.RoomId) .Cascade(CascadeMode.Stop) .NotEmpty() .MustAsync(async(roomId, cancellation) => { return(await _roomsRepository.IsRoomExistsAsync(roomId)); }) .WithMessage("Room with this id doesn't exists."); RuleFor(booking => booking.BookingDates) .NotNull() .Must(BeAValidDates) .WithMessage("Dates are incorrect"); RuleFor(booking => booking.NumberOfPerson) .NotEmpty() .LessThanOrEqualTo(booking => GetMaxNumberOfPersonInRoom(booking.RoomId)) .GreaterThan(0); }