Ejemplo n.º 1
0
/*        protected virtual IQueryable<Product> CreateQueryable(PagedAndSortedResultRequestDto input)
 *      {
 *          return _productRepository.GetAll();
 *      }*/

        public async Task <PagedResultDto <ProductDto> > GetAllProducts(GetAllProductsInput input)
        //public async Task<PagedResultDto<ProductDto>> GetAll(PagedAndSortedResultRequestDto input) //todo study AsyncCrudAppService in modular-to-do-app

        {
            //todo use  AsyncHelper.RunSync()
            var totalCount = await _productRepository.GetAll()
                             .WhereIf(input.Category != null && input.Category != "Products", p => p.Category == input.Category)
                             .CountAsync();

            //var totalCount2 = await _productRepository.GetAllListAsync();

            var products = await _productRepository
                           .GetAll()
                           .WhereIf(input.Category != null && input.Category != "Products", p => p.Category == input.Category)
                           .OrderBy(p => p.Category)
                           .Skip((input.SkipCount - 1) * _pageSize)
                           .Take(input.MaxResultCount)
                           .ToListAsync();

/*            var mappedProducts =
 *              ObjectMapper.Map<List<ProductDto>>(products); //todo make sure output list contains (hiiden in view) ids*/

/*            var mappedProducts =
 *              ObjectMapper.Map<List<ProductDto>>(products);*/

            var mappedProducts = products.MapTo <List <ProductDto> >();

            var retVal = new PagedResultDto <ProductDto>(totalCount, mappedProducts);

            return(retVal);
        }
Ejemplo n.º 2
0
        public async Task <PagedResultDto <GetProductForViewDto> > GetAll(GetAllProductsInput input)
        {
            var filteredProducts = _productRepository.GetAll()
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Description.Contains(input.Filter))
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.DescriptionFilter), e => e.Description.ToLower() == input.DescriptionFilter.ToLower().Trim());

            var pagedAndFilteredProducts = filteredProducts
                                           .OrderBy(input.Sorting ?? "id asc")
                                           .PageBy(input);

            var products = from o in pagedAndFilteredProducts
                           select new GetProductForViewDto()
            {
                Product = new ProductDto
                {
                    Description = o.Description,
                    Id          = o.Id
                }
            };

            var totalCount = await filteredProducts.CountAsync();

            return(new PagedResultDto <GetProductForViewDto>(
                       totalCount,
                       await products.ToListAsync()
                       ));
        }
Ejemplo n.º 3
0
        public IEnumerable <ProductDto> GetAll(GetAllProductsInput input)
        {
            var filterInput = Mapper.Map <ProductFilterInput>(input);
            var products    = _productRepository.GetAllProducts(filterInput);
            var result      = Mapper.Map <IEnumerable <ProductDto> >(products);

            return(result);
        }
Ejemplo n.º 4
0
        public IActionResult GetActive(GetAllProductsInput input)
        {
            var dto = _service.GetAll(input);

            if (dto == null)
            {
                return(NotFound());
            }
            return(Ok(dto));
        }
Ejemplo n.º 5
0
/*
 *      public ActionResult List(GetAllProductsInput input, int page)
 *      {
 *          input.SkipCount = page;
 *          var output = _productService.GetAllSync(input);
 *          var pagingInfo = new PagingInfo(input.SkipCount, input.MaxResultCount, output.TotalCount);
 *          var category = input.Category == null ? "Products" : input.Category;
 *          var model = new ProductListViewModel(output.Items, pagingInfo, category);
 *          return View(model);
 *      }
 */

        public async Task <ActionResult> List(GetAllProductsInput input, int page)
        {
            input.SkipCount = page;
            var output = await _productAppService.GetAllProducts(input);

            var pagingInfo = new PagingInfo(input.SkipCount, input.MaxResultCount, output.TotalCount);
            var category   = input.Category == null ? "Products" : input.Category;
            var model      = new ProductListViewModel(output.Items, pagingInfo, category);

            return(View(model));
        }
        public async Task <PagedResultDto <GetProductForViewDto> > GetAll(GetAllProductsInput input)
        {
            var filteredProducts = _productRepository.GetAll()
                                   .Include(e => e.CategoryFk)
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Name.Contains(input.Filter) || e.Description.Contains(input.Filter) || e.Uom.Contains(input.Filter) || e.Remark.Contains(input.Filter))
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.NameFilter), e => e.Name == input.NameFilter)
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.DescriptionFilter), e => e.Description == input.DescriptionFilter)
                                   .WhereIf(input.MinStockFilter != null, e => e.Stock >= input.MinStockFilter)
                                   .WhereIf(input.MaxStockFilter != null, e => e.Stock <= input.MaxStockFilter)
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.UomFilter), e => e.Uom == input.UomFilter)
                                   .WhereIf(input.IsApprovedFilter > -1, e => (input.IsApprovedFilter == 1 && e.IsApproved) || (input.IsApprovedFilter == 0 && !e.IsApproved))
                                   .WhereIf(input.IsActiveFilter > -1, e => (input.IsActiveFilter == 1 && e.IsActive) || (input.IsActiveFilter == 0 && !e.IsActive))
                                   .WhereIf(!string.IsNullOrWhiteSpace(input.CategoryNameFilter), e => e.CategoryFk != null && e.CategoryFk.Name == input.CategoryNameFilter);

            var pagedAndFilteredProducts = filteredProducts
                                           .OrderBy(input.Sorting ?? "id asc")
                                           .PageBy(input);

            var products = from o in pagedAndFilteredProducts
                           join o1 in _lookup_categoryRepository.GetAll() on o.CategoryId equals o1.Id into j1
                           from s1 in j1.DefaultIfEmpty()

                           select new GetProductForViewDto()
            {
                Product = new ProductDto
                {
                    Name        = o.Name,
                    Description = o.Description,
                    Stock       = o.Stock,
                    Uom         = o.Uom,
                    IsApproved  = o.IsApproved,
                    IsActive    = o.IsActive,
                    Remark      = o.Remark,
                    Id          = o.Id
                },
                CategoryName = s1 == null ? "" : s1.Name.ToString()
            };

            var totalCount = await filteredProducts.CountAsync();

            return(new PagedResultDto <GetProductForViewDto>(
                       totalCount,
                       await products.ToListAsync()
                       ));
        }
Ejemplo n.º 7
0
 public ActionResult Index(GetAllProductsInput input)//can be removed? todo change routing and make redirect to action List
 {
     return(View());
 }