private void ValidateUser(UserProxy user) { if (user == null) { ThrowHttp.BadRequest(ErrorMessage.USER_REQUIRED); } var emailError = _emailValidator.Validate(user.Email); if (emailError != null) { ThrowHttp.BadRequest(emailError); } var passwordError = _passwordValidator.Validate(user.Password); if (passwordError != null) { ThrowHttp.BadRequest(passwordError); } if (string.IsNullOrWhiteSpace(user.FirstName)) { ThrowHttp.BadRequest(ErrorMessage.FIRST_NAME_REQUIRED); } if (string.IsNullOrWhiteSpace(user.LastName)) { ThrowHttp.BadRequest(ErrorMessage.LAST_NAME_REQUIRED); } }
public async Task <User> GetByEmailAsync(string email) { if (string.IsNullOrWhiteSpace(email)) { ThrowHttp.BadRequest(CommonErrorMessage.EMAIL_REQUIRED); } return(await _repository.GetByEmailAsync(email)); }
public async Task <PageResponse <AuthorProxy> > GetAuthorPageAsync(PageRequest pageRequest) { var pageError = _pageValidator.Validate(pageRequest); if (pageError != null) { ThrowHttp.BadRequest(pageError); } var page = await _repository.GetPageAsync(pageRequest); var total = await _repository.GetCountAsync(); return(new PageResponse <AuthorProxy>(page.Select(MapToProxy).ToArray(), total)); }
private void ValidateCredentials(CredentialProxy credentials) { if (credentials == null) { ThrowHttp.BadRequest(ErrorMessage.CREDENTIALS_REQUIRED); } if (string.IsNullOrWhiteSpace(credentials.Email)) { ThrowHttp.BadRequest(CommonErrorMessage.EMAIL_REQUIRED); } if (string.IsNullOrWhiteSpace(credentials.Password)) { ThrowHttp.BadRequest(CommonErrorMessage.PASSWORD_REQUIRED); } }
private void Validate(BookProxy book) { if (book == null) { ThrowHttp.BadRequest(ErrorMessage.BOOK_REQUIRED); } if (string.IsNullOrWhiteSpace(book.Title)) { ThrowHttp.BadRequest(ErrorMessage.TITLE_REQUIRED); } var dateError = _dateValidator.Validate(book.PublishDate); if (dateError != null) { ThrowHttp.BadRequest(dateError); } }
private void Validate(AuthorProxy author) { if (author == null) { ThrowHttp.BadRequest(ErrorMessage.AUTHOR_REQUIRED); } if (string.IsNullOrWhiteSpace(author.FirstName)) { ThrowHttp.BadRequest(ErrorMessage.FIRST_NAME_REQUIRED); } if (string.IsNullOrWhiteSpace(author.LastName)) { ThrowHttp.BadRequest(ErrorMessage.LAST_NAME_REQUIRED); } if (!author.NobelPrize.HasValue) { ThrowHttp.BadRequest(ErrorMessage.NOBEL_PRIZE_REQUIRED); } var dateOfBirthError = _dateValidator.Validate(author.DateOfBirth); if (dateOfBirthError != null) { ThrowHttp.BadRequest(dateOfBirthError); } if (string.IsNullOrWhiteSpace(author.DateOfDeath)) { return; } var dateOfDeathError = _dateValidator.Validate(author.DateOfDeath); if (dateOfDeathError != null) { ThrowHttp.BadRequest(dateOfDeathError); } }