public async Task <IActionResult> GetAllProducts([FromQuery] PagingModel paging) { try { var client = _bus.CreateRequestClient <IGetAllProductsCommand, IAllProductRetrievedEvent>( _serviceAddress, TimeSpan.FromSeconds(60)); var getProductsCommand = new GetAllProductsCommand(paging.PageSize, paging.CurrentPage, paging.SortBy, paging.SortDirection); var response = await client.Request(getProductsCommand); if (paging.CurrentPage != null && paging.PageSize.HasValue) { var totalCount = response.Products?.Count ?? 0; var totalPages = (int)Math.Ceiling(totalCount / (double)paging.PageSize); return(Ok(new { TotalCount = totalCount, totalPages, ds = response.Products })); } return(Ok(response?.Products)); } catch (Exception e) { return(BadRequest($"Can't get the products: {e.Message}")); } }
public IActionResult GetAll() { GetAllProductsCommand command = new GetAllProductsCommand(); serviceProcessor.Process(command); IEnumerable <ProductViewModel> models = ModelMapper.MapCollection <Product, ProductViewModel>(command.Result); return(Ok(models)); }
public List <Product> GetAll() { // Execute Business validation var products = new List <Product>(); var command = new GetAllProductsCommand(UnitOfWork, products); DataBusManager.ExecuteCommand(command); if (command.Success) { // Success execution } else if (command.Fail) { // Fail Execution } return(command.Products); }
public async Task <List <Product> > Handle(GetAllProductsCommand request, CancellationToken cancellationToken) { var result = await unitOfWork.ProductRepository.Get(); return(result); }
public async Task <IActionResult> GetAllProducts(GetAllProductsCommand query) { var response = await mediator.Send(query); return(Ok(response)); }
public Task <IEnumerable <Product> > Handle(GetAllProductsCommand request, CancellationToken cancellationToken) { return(Task.FromResult(this.productsDataProvider.GetAll())); }