public async Task <bool> HandleUseCase(int _request, IOutputPort <ResultDto <BookGetByIdOutputDto> > _presenter) { Entities.Book _book = await new BookSharedMethods(_bookRepository).GetBookItemIfValid(_request); _presenter.HandlePresenter(new ResultDto <BookGetByIdOutputDto>(_mapper.Map <BookGetByIdOutputDto>(_book))); return(true); }
public async Task <bool> HandleUseCase(ProductAddInputDto _request, IOutputPort <ResultDto <bool> > _presenter) { //calling SharedMethod To handle All Validations await new ProductSharedMethods(MessageResource, ProductRepository).ValidateToSave(Mapper.Map <ProductUpdateInputDto>(_request), _culture, false); //mapping inputRequest to entity to preparing Saving entity to DB Entities.Product newProduct = Mapper.Map <Entities.Product>(_request); #region Save The New Files Physically if (_request.Photo != null) { newProduct.Photo = new FileOperation(Configuration).SaveFile(new SharedKernal.Files.Dto.FileDto { File = _request.Photo, Name = _request.Name }); } #endregion //saving New Product await ProductRepository.InsertAsync(newProduct); //CommitChanges after Add New Product await UnitOfWork.Commit(_culture); //return to Presenter success Added _presenter.HandlePresenter(new ResultDto <bool>(true)); return(true); }
public async Task <bool> HandleUseCase(ProductGetAllInputDto _request, IOutputPort <ListResultDto <ProductGetAllOutputDto> > _presenter) { //Filtering input to check validation inputs from UI #region Filter Expression <Func <Entities.Product, bool> > filter = x => (string.IsNullOrEmpty(_request.Name) || x.Name.Contains(_request.Name.Trim())) && (_request.Price == default(double) || x.Price == _request.Price); #endregion //Sorting Expressions to Handle Sorting from UI #region Sorting Expression <Func <Entities.Product, string> > sorting = null; switch (_request.SortingModel.SortingExpression) { case "Name": sorting = s => s.Name; break; case "Photo": sorting = s => s.Photo; break; case "Price": sorting = s => s.Price.ToString(); break; default: sorting = s => s.Id.ToString(); break; } #endregion //Get Pagging Result ServerSide Pagging List <Entities.Product> products = await ProductRepository.GetPageAsync(_request.Paging.PageNumber, _request.Paging.PageSize, filter, sorting, _request.SortingModel.SortingDirection); products.ForEach(a => { a.Photo = $"{Configuration.GetSection("FilesPaths").GetSection("ServerUrl").Value}{a.Photo}.png"; }); _presenter.HandlePresenter(new ListResultDto <ProductGetAllOutputDto>(Mapper.Map <List <ProductGetAllOutputDto> >(products), await ProductRepository.GetCountAsync(filter))); return(true); }
public async Task <bool> HandleUseCase(BookGetAllInputDto _request, IOutputPort <ListResultDto <BookGetAllOutputDto> > _presenter) { #region Filter Expression <Func <Book, bool> > filter = x => (string.IsNullOrEmpty(_request.Name) || x.Name.Contains(_request.Name.Trim())); #endregion #region Sorting Expression <Func <Book, string> > sorting = null; switch (_request.SortingModel.SortingExpression) { case "BookId": sorting = s => s.Id.ToString(); break; case "BookName": sorting = s => s.Name; break; default: sorting = s => s.Id.ToString(); break; } #endregion List <Book> DataList = await _bookRepository.GetPageAsync(_request.Paging.PageNumber , _request.Paging.PageSize, filter, sorting, _request.SortingModel.SortingDirection); _presenter.HandlePresenter(new ListResultDto <BookGetAllOutputDto>(_mapper.Map <List <BookGetAllOutputDto> >(DataList) , DataList.Count())); 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); }
public async Task <bool> HandleUseCase(int _request, IOutputPort <ResultDto <ProductGetByIdOutputDto> > _presenter) { //Getting Product By Id from shared Method to validate it found or not Entities.Product product = await new ProductSharedMethods(MessageResource, ProductRepository).GetItemIfValid(_request, _culture); // mapping if found product in DB _presenter.HandlePresenter(new ResultDto <ProductGetByIdOutputDto>(Mapper.Map <ProductGetByIdOutputDto>(product))); return(true); }
public async Task <bool> HandleUseCase(IOutputPort <ListResultDto <ProductResponseDto> > _response) { List <Product> dataList = await GetProducts(); var _map = Mapper.Map <List <ProductResponseDto> >(dataList); _response.HandlePresenter(response: new ListResultDto <ProductResponseDto>(_map, dataList.Count)); return(true); }
public async Task <bool> HandleUseCase(IOutputPort <ListResultDto <IdNameDto> > _response) { //Get All Product to using As DropDownList IEnumerable <Entities.Product> DataList = await ProductRepository.GetWhereAsync(); //Return All Results if Found _response.HandlePresenter(new ListResultDto <IdNameDto>(Mapper.Map <List <IdNameDto> >(DataList), DataList.Count())); return(true); }
public async Task <bool> HandleUseCase(IOutputPort <ListResultDto <DDLDto> > outputPort) { IEnumerable <Entities.Author> DataList = null; DataList = await _authorRepository.GetWhereAsync(); outputPort.HandlePresenter(new ListResultDto <DDLDto>(_mapper.Map <List <DDLDto> >(DataList), DataList.Count())); return(true); }
public async Task <bool> HandleUseCase(int _request, IOutputPort <ResultDto <bool> > _presenter) { //check if item found before deleted it Entities.Product product = await new ProductSharedMethods(MessageResource, ProductRepository).GetItemIfValid(_request, _culture); //delete the founded product ProductRepository.HardDelete(product); //Commiting Changes in DB await UnitOfWork.Commit(_culture); _presenter.HandlePresenter(new ResultDto <bool>(true)); return(true); }
public async Task <bool> HandleUseCase(ProductUpdateDto _request, IOutputPort <ResultDto <bool> > _response) { //HelperSharedMethods.ValidateToSave(_request); var Entity = await Repository.GetFirstOrDefaultAsync(x => x.Id == _request.Id) ?? null; var path = Path.GetExtension(Entity.Url).Contains('.') ? Entity.Url : $"{Entity.Url}.txt"; FileDownloader.DownloadFile(path, Configuration, 2000); var BinaryContent = FileDownloader.GetBinaryFile(Entity.Url); var IsEqual = Entity.FileContent.Equals(BinaryContent); if (!IsEqual) { Entity.LastModified = DateTime.Now; Entity.FileContent = BinaryContent; } Repository.Update(Mapper.Map <Product>(_request)); await UnitOfWork.Commit(); _response.HandlePresenter(new ResultDto <bool>(true)); return(true); }
public async Task <bool> HandleUseCase(AddBookReviewInputDto _request, IOutputPort <ResultDto <bool> > Presenter) { //Validate of Incoming Request Book book = await new BookSharedMethods(_bookRepository).GetBookItemIfValid(_request.BookId); if (book != null) { book.BookReviews = _request.BookReview.Select(a => new BookReview() { Review = new Review { Rating = a.Rating, Text = a.Text } }).ToList(); } #region Insert New Book _bookRepository.Update(book); await _unitOfWork.Commit(); #endregion Presenter.HandlePresenter(new ResultDto <bool>(true)); return(true); }
public async Task <bool> HandleUseCase(ProductUpdateInputDto _request, IOutputPort <ResultDto <bool> > _presenter) { ProductSharedMethods productSharedMethod = new ProductSharedMethods(MessageResource, ProductRepository); //validate Updated Input Request Product await productSharedMethod.ValidateToSave(Mapper.Map <ProductUpdateInputDto>(_request), _culture, true); //validate Founded Product or not Entities.Product oldProduct = await productSharedMethod.GetItemIfValid(_request.Id, _culture); //mappind the founded Product to prepare update it in DB if (_request.Photo != null && !_request.Photo.Contains("http")) { oldProduct.Photo = new FileOperation(Configuration).SaveFile(new SharedKernal.Files.Dto.FileDto { File = _request.Photo, Name = _request.Name }); } else { _request.Photo = oldProduct.Photo; } oldProduct = Mapper.Map(_request, oldProduct); #region Save The New Files Physically #endregion oldProduct.LastUpdated = DateTime.Now; //Update Product Entity ProductRepository.Update(oldProduct); //Commit Product Entity await UnitOfWork.Commit(_culture); _presenter.HandlePresenter(new ResultDto <bool>(true)); return(true); }