internal async Task <bool> ValidateToSave(AddBookInputDto _request) { #region User Input Validation if (_request == null) { throw new ValidationsException("InvalidRequest"); } else if (string.IsNullOrWhiteSpace(_request.Name)) { throw new ValidationsException("Name Is Required"); } else if (string.IsNullOrWhiteSpace(_request.Category)) { throw new ValidationsException("Category Is Required"); } else if (string.IsNullOrWhiteSpace(_request.Price)) { throw new ValidationsException("Price Is Required"); } else if (_request.AuthorId <= default(int)) { throw new ValidationsException("Author Is Required"); } #endregion #region Db Validation else if (!await GetAuthorIfFound(_request.AuthorId)) { throw new ValidationsException("Author Not Found in Our DataBase"); } #endregion return(true); }
public async Task <bool> HandleUseCase(AddBookInputDto _request, IOutputPort <ResultDto <bool> > Presenter) { //Validate of Incoming Request await new BookSharedMethods(_authorRepository).ValidateToSave(_request); #region Insert New Book Book book = _mapper.Map <Book>(_request); await _bookRepository.InsertAsync(book); if (_request.BookReview?.Any() ?? default) { book.BookReviews = _request.BookReview.Select(a => new BookReview() { Review = new Review { Rating = a.Rating, Text = a.Text } }).ToList(); } await _unitOfWork.Commit(); #endregion Presenter.HandlePresenter(new ResultDto <bool>(true)); return(true); }