Ejemplo n.º 1
0
        public async Task <IActionResult> GetProducts(Int32?pageSize = 10, Int32?pageNumber = 1, String name = null)
        {
            var response = new ListModelResponse <ProductViewModel>() as IListModelResponse <ProductViewModel>;

            try
            {
                response.PageSize   = (Int32)pageSize;
                response.PageNumber = (Int32)pageNumber;

                response.Model = await Task.Run(() =>
                {
                    return(AdventureWorksRepository
                           .GetProducts(response.PageSize, response.PageNumber, name)
                           .Select(item => item.ToViewModel())
                           .ToList());
                });

                response.Message = String.Format("Total of records: {0}", response.Model.Count());
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 2
0
        public IListModelResponse <ProductViewModel> Handle(ProductRequest message)
        {
            var response = new ListModelResponse <ProductViewModel>() as IListModelResponse <ProductViewModel>;

            try
            {
                response.PageNumber = message.PageNumber;
                response.PageSite   = message.PageSize;
                response.Model      = _Repository.GetProducts(message.PageSize, message.PageNumber, message.Name)
                                      .Select(item => item.ToViewModel())
                                      .ToList();
            }
            catch (Exception e)
            {
                response.DidError = true;
                response.Message  = e.Message;
            }
            return(response);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetAllProducts(Int32 pageSize = 10, Int32 pageNumber = 1, String name = null)
        {
            var response = new ListModelResponse <ProductViewModel>() as IListModelResponse <ProductViewModel>;

            try
            {
                response.PageNumber = pageNumber;
                response.PageSite   = pageSize;
                response.Model      = await _Repository.GetProducts(pageSize, pageNumber, name)
                                      .Select(item => item.ToViewModel())
                                      .ToListAsync();
            }
            catch (Exception e)
            {
                response.DidError = true;
                response.Message  = e.Message;
            }

            return(response.ToHttpResponse());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetProductsAsync(int?pageSize = null, int?pageNumber = null, string name = null)
        {
            var products = new ListModelResponse <ProductViewModel>();

            try
            {
                var response = await AdventureWorksRepository
                               .GetProducts(pageSize, pageNumber, name);

                products.Model      = response.Model.Select(item => item.ToViewModel()).ToList();
                products.TotalCount = response.TotalCount;
                products.Message    = string.Format($"Showing {response.Model?.Count()} of total {response.TotalCount} items.");
                _logger?.LogInfo("Products: " + products.Message);
            }
            catch (Exception ex)
            {
                products.DidError     = true;
                products.ErrorMessage = ex.Message;
                _logger.LogError(ex.Message);
            }

            return(products.ToHttpResponse());
        }
Ejemplo n.º 5
0
        public IActionResult GetById(int id)
        {
            var result = _repository.GetProducts(id);

            return(Ok(result));
        }
 public IActionResult Get()
 {
     return(Ok(_repository.GetProducts()));
 }