Ejemplo n.º 1
0
        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}"));
            }
        }
Ejemplo n.º 2
0
        public IActionResult GetAll()
        {
            GetAllProductsCommand command = new GetAllProductsCommand();

            serviceProcessor.Process(command);
            IEnumerable <ProductViewModel> models = ModelMapper.MapCollection <Product, ProductViewModel>(command.Result);

            return(Ok(models));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public async Task <List <Product> > Handle(GetAllProductsCommand request, CancellationToken cancellationToken)
        {
            var result = await unitOfWork.ProductRepository.Get();

            return(result);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> GetAllProducts(GetAllProductsCommand query)
        {
            var response = await mediator.Send(query);

            return(Ok(response));
        }
Ejemplo n.º 6
0
 public Task <IEnumerable <Product> > Handle(GetAllProductsCommand request, CancellationToken cancellationToken)
 {
     return(Task.FromResult(this.productsDataProvider.GetAll()));
 }