示例#1
0
        public async Task <IActionResult> GetProductsForSearching([FromQuery] ProductParams productParams)
        {
            if (productParams.PageNumber < 1 || productParams.PageSize < 1)
            {
                return(BadRequest("PageNumber or PageSize is less then 1"));
            }

            var products = await _unitOfWork.Product.GetProductsForSearchingAsync(productParams);

            if (products == null)
            {
                return(NotFound());
            }
            else if (products.PageSize < 1 || products.TotalCount < 0 || products.TotalPages < 1 || products.CurrentPage < 1)
            {
                return(BadRequest("Pagination parameters wasn't set properly"));
            }

            var productToReturn = _mapper.Map <IEnumerable <ProductForSearchingDto> >(products);

            Response.AddPagination(products.CurrentPage, products.PageSize,
                                   products.TotalCount, products.TotalPages);

            return(Ok(productToReturn));
        }
        public async Task <PagedList <ProductModel> > GetAllAsync(ProductParams productParams)
        {
            var products = _dataContext.Products.OrderBy(p => p.Id);

            if (!string.IsNullOrEmpty(productParams.OrderBy))
            {
                switch (productParams.OrderBy)
                {
                case "Alphabetically":
                    products = products.OrderBy(p => p.Name);
                    break;

                case "Cheap":
                    products = products.OrderBy(p => p.Price);
                    break;

                case "Expensive":
                    products = products.OrderByDescending(p => p.Price);
                    break;

                default:
                    products = products.OrderBy(p => p.Id);
                    break;
                }
            }

            return(await PagedList <ProductModel> .CreateListAsync(products, productParams.PageSize, productParams.PageNumber));
        }
示例#3
0
        public async Task <IActionResult> GetProductsForModeration([FromQuery] ProductParams productParams)
        {
            if (productParams.PageNumber < 1 || productParams.PageSize < 1)
            {
                return(BadRequest("PageNumber or PageSize is less then 1"));
            }

            //var categoryId = (int)_ctx.Entry<Product>(await _ctx.Products.FirstOrDefaultAsync()).Property("CategoryId").CurrentValue;
            var products = await _unitOfWork.Product.GetProductsForModerationAsync(productParams);

            if (products == null)
            {
                return(NotFound());
            }
            else if (products.PageSize < 1 || products.TotalCount < 0 || products.TotalPages < 1 || products.CurrentPage < 1)
            {
                return(BadRequest("Pagination parameters wasn't set properly"));
            }

            var productsToReturn = _mapper.Map <IEnumerable <ProductForModerationDto> >(products);

            Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);

            return(Ok(productsToReturn));
        }
        public new async Task <PagedList <Product> > ListAsync(ProductParams productParams)
        {
            var query = context.Products.Include(p => p.Category).OrderByDescending(p => p.Name).AsQueryable();

            if (!string.IsNullOrEmpty(productParams.OrderBy))
            {
                switch (productParams.OrderBy)
                {
                case "low":
                    query = query.OrderByDescending(p => p.Name);
                    break;

                default:
                    query = query.OrderBy(p => p.Name);
                    break;
                }
            }

            if (!string.IsNullOrEmpty(productParams.CategoryName))
            {
                query = query.Where(p => p.Category.Name == productParams.CategoryName);
            }

            return(await PagedList <Product> .CreateAsync(query, productParams.PageNumber, productParams.PageSize));
        }
示例#5
0
        public async Task <ActionResult <IEnumerable <ProductDTO> > > GetProducts([FromQuery] ProductParams productParams)
        {
            var query = _context.Products.AsQueryable();

            if (!string.IsNullOrEmpty(productParams.Name))
            {
                query = query.Where(p => p.Name == productParams.Name);
            }

            if (productParams.Price.HasValue)
            {
                query = query.Where(p => p.Price == productParams.Price);
            }

            if (productParams.IsAvailable.HasValue)
            {
                query = query.Where(p => p.IsAvailable == productParams.IsAvailable);
            }

            return(await query.Select(x =>
                                      productsDTO(x))
                   .Skip((productParams.PageNumber - 1) * productParams.PageSize)
                   .Take(productParams.PageSize)
                   .ToListAsync());
        }
示例#6
0
        public void IntegrationTest_Given_ProductParams_When_GetProductsForModerationAsync_ThenReturn_PagedListOfProductForModerationDto(int pageSize, int pageNumber, int expectedCount)
        {
            //Arrange
            var expected = Data.ProductForModerationDto().Skip((pageNumber - 1) * pageSize).Take(pageSize);

            var productParams = new ProductParams()
            {
                PageNumber = pageNumber,
                PageSize   = pageSize
            };

            var sut = new ProductRepository(_context);


            //Act
            var result = sut.GetProductsForModerationAsync(productParams).Result;

            //Assert
            result.Should().NotBeNull();

            result.Should().BeOfType <PagedList <ProductForModerationDto> >();

            result.Should().BeEquivalentTo(expected);

            result.Count().Should().Be(expectedCount);
        }
示例#7
0
        public void IntegrationTest_Given_DefaultProductParams_When_GetProductsForSearching_Then_Returns_Ok_With_PagedProducts()
        {
            //Arrange

            var httpContext = new DefaultHttpContext();

            var expected = Data.ProductForSearchingDto();

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext
            };

            var sut = new ProductsController(_mapper, _unitOfWork)
            {
                ControllerContext = controllerContext
            };

            var productParams = new ProductParams();

            //Act
            var result = sut.GetProductsForSearching(productParams).Result;


            //Assert
            result.Should().BeOfType(typeof(OkObjectResult));

            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(expected);
        }
        public async Task <IActionResult> GetAllProducts_Admin([FromQuery] ProductParams productParams)
        {
            var productsFromRepo = await _unitOfWork.Products.GetAllProducts_Admin(productParams);

            var productToReturn = _mapper.Map <IEnumerable <ProductForReturnDto> >(productsFromRepo);

            return(Ok(productToReturn));
        }
示例#9
0
        public async Task <ActionResult <PagedList <ProductDto> > > GetProducts([FromQuery] ProductParams productsParams)
        {
            var products = await _unitOfWork.ProductRepo.GetProductsAsync(productsParams);

            Response.AddPaginationHeader(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);

            return(products);
        }
        public async Task <IActionResult> Get([FromQuery] ProductParams productParams)
        {
            var products = await this._repo.GetProductsAsync(productParams);

            Response.AddPaginationHeader(products.CurrentPage, products.PageSize,
                                         products.TotalCount, products.TotalPages);

            return(Ok(products.ToProductViewModelList()));
        }
示例#11
0
        public async Task <IActionResult> GetProducts([FromQuery] ProductParams productParams)
        {
            var products = await _repo.GetProducts(productParams);

            var productsToReturn = _mapper.Map <IEnumerable <ProductForListDto> >(products);

            Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);
            return(Ok(productsToReturn));
        }
        //get all products
        public async Task <IActionResult> GetProducts([FromQuery] ProductParams productParams)
        {
            //get products and general data for filters and lists
            var products = await _repo.GetProducts(productParams);

            var generalDataFromRepo = await _repo.GetGeneralData();

            var productsToReturn    = _mapper.Map <IEnumerable <ProductForHomeDto> >(products);
            var generalDataToReturn = _mapper.Map <DataForHomeDto>(generalDataFromRepo);
            //get all products without paging for calculation of counters
            // var itemsBeforePaging = _mapper.Map<IEnumerable<ProductForHomeDto>>(products.AllItems);

            //calculate filters for current products list - currently not in use
            // foreach (var year in generalDataToReturn.Years)
            // {
            //     year.FilteredCounter = itemsBeforePaging.Where(p => p.YearOfCreation == year.Title).Count();
            // }
            // foreach (var degree in generalDataToReturn.Degree)
            // {
            //     degree.FilteredCounter = itemsBeforePaging.Where(p => p.Degree == degree.Title).Count();
            // }
            // foreach (var course in generalDataToReturn.Courses)
            // {
            //     course.FilteredCounter = itemsBeforePaging.Where(p => p.Courses.Any(c => c.Id == course.Id)).Count();
            // }
            // foreach (var org in generalDataToReturn.Organizations)
            // {
            //     org.FilteredCounter = itemsBeforePaging.Where(p => p.OrganizationId == org.Id).Count();
            // }
            // foreach (var orgType in generalDataToReturn.OrganizationTypes)
            // {
            //     orgType.FilteredCounter = itemsBeforePaging.Where(p => p.OrganizationTypes.Any(ot => ot.Id == orgType.Id)).Count();
            // }
            // foreach (var lect in generalDataToReturn.Lecturers)
            // {
            //     lect.FilteredCounter = itemsBeforePaging.Where(p => p.Lecturers.Any(l => l.Id == lect.Id)).Count();
            // }
            // foreach (var task in generalDataToReturn.Tasks)
            // {
            //     task.FilteredCounter = itemsBeforePaging.Where(p => p.TaskId == task.Id).Count();
            // }
            // foreach (var pt in generalDataToReturn.ProductTypes)
            // {
            //     pt.FilteredCounter = itemsBeforePaging.Where(p => p.ProductTypeId == pt.Id).Count();
            // }

            //set all data in one class
            var rootData = new RootForHomeDto();

            rootData.Products    = productsToReturn;
            rootData.GeneralData = generalDataToReturn;

            //add pagination headers
            Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);

            return(Ok(rootData));
        }
示例#13
0
        public async Task <ActionResult <IEnumerable <ProductDto> > > GetProducts([FromQuery] ProductParams productParams)
        {
            var products = await _productRepository.GetProductsDtoAsync(productParams);

            Response.AddPaginationHeader(products.CurrentPage, products.PageSize,
                                         products.TotalCount, products.TotalPages);

            return(Ok(products));
        }
        private void next_Click(object sender, RoutedEventArgs e)
        {
            var parameters = new ProductParams();

            parameters.Path     = textBlock.Text;
            parameters.Name     = textBlock1.Text;
            parameters.Category = textBox.Text;
            this.Frame.Navigate(typeof(addProductMaterial), parameters);
        }
示例#15
0
        public async Task <PagedList <Product> > GetProducts(ProductParams productParams)
        {
            var products = _context.Products.Include(p => p.SubCategory).Include(s => s.Vendor).Include(w => w.PhotoForProducts).AsQueryable();

            products = products.Where(f => (f.ProductNumber == productParams.ProductNumber ||
                                            f.ProductNameEnglish == productParams.ProductNameEnglish ||
                                            f.ProductNameArabic == productParams.ProductNameArabic));
            return(await PagedList <Product> .CreateAsync(products, productParams.PageNumber, productParams.PageSize));
        }
示例#16
0
        public async Task <IActionResult> Get(ProductParams param)
        {
            var product = await _productRepo.GetProductList(param);

            Response.AddPagination(product.CurrentPage, product.PageSize,
                                   product.TotalCount, product.TotalPages);

            return(Ok(product));
        }
        public async Task <IActionResult> GetProducts([FromQuery] ProductParams productParams)
        {
            var products = await _productRepo.GetProducts(productParams);

            var productsInPage = _mapper.Map <ICollection <ProductListDto> >(products);

            Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);

            return(Ok(productsInPage));
        }
示例#18
0
        public PagedList <Product> GetProductByCategory(ProductParams productParams, string category)
        {
            var products = _ctx.Product.Include(p => p.Photos).Include("ProductSizes")
                           .Include("ProductSizes.ProductSizeColor")
                           .Include("ProductSizes.Size").
                           Include("ProductSizes.ProductSizeColor.Color");
            var productsToReturn = products.Where(x => x.Active == "Ενεργοποιημένο").Where(y => y.Category == category).OrderBy(y => y.Code);

            return(PagedList <Product> .Create(productsToReturn, productParams.PageNumber, productParams.PageSize));
        }
示例#19
0
        public PagedList <Product> GetProductByLine(ProductParams productParams, string line)
        {
            var products = _ctx.Product.Include(p => p.Photos).Include("ProductSizes")
                           .Include("ProductSizes.ProductSizeColor")
                           .Include("ProductSizes.Size").Include(p => p.Photos).
                           Include("ProductSizes.ProductSizeColor.Color");
            var productsToReturn = products.Where(x => x.Active == "Ενεργοποιημένο").Where(x => x.Line == line);

            return(PagedList <Product> .Create(productsToReturn, productParams.PageNumber, productParams.PageSize));
        }
示例#20
0
        public async Task <PagedList <Product> > GetAllProducts(ProductParams productParams)
        {
            //   var products=await _context.Product.Include(h=>h.ca).ThenInclude(x=>x.PhotosProduct)
            //   .Where(s=>s.Id==s.Product.FirstOrDefault().CategoryId).ToListAsync();
            //   return products;


            var getAllItems = _context.Products.Include(ax => ax.PhotosProduct).Include(x => x.Category);

            return(await PagedList <Product> .createAsync(getAllItems, productParams.PageNumber, productParams.PageSize));
        }
示例#21
0
        public async Task <IActionResult> GetAllProduct([FromQuery] ProductParams productParams)
        {
            var Allproduct = await _Rep.GetAllProducts(productParams);

            var productToList = _mapper.Map <IEnumerable <ProductForListDto> >(Allproduct);

            Response.AddPagination(Allproduct.CurrentyPage, Allproduct.PageSize
                                   , Allproduct.TotalCount, Allproduct.TotalPages);

            return(Ok(productToList));
        }
示例#22
0
        private void next_Click(object sender, RoutedEventArgs e)
        {
            var parameter = new ProductParams();

            parameter.Path     = textBlock2.Text;
            parameter.Name     = textBlock.Text;
            parameter.Category = textBlock1.Text;
            parameter.Material = textBlock3.Text;
            parameter.Price    = textBox.Text;
            this.Frame.Navigate(typeof(addProductSummary), parameter);
        }
示例#23
0
        public async Task <PagedList <ProductDto> > GetProductsAsync(ProductParams productParams)
        {
            var query = _context.Products
                        .AsNoTracking()
                        .OrderByDescending(m => m.Modified)
                        .ProjectTo <ProductDto>(_mapper.ConfigurationProvider)
                        .AsQueryable();

            query = query.Where(p => EF.Functions.Like(p.Name, $"%{productParams.SearchString}%"));

            return(await PagedList <ProductDto> .CreateAsync(query, productParams.PageNumber, productParams.PageSize));
        }
示例#24
0
        public async Task <PagedList <Product> > GetProductList(ProductParams prod)
        {
            var products = _context.Products.Where(p =>
                                                   prod.SearchString != null &&
                                                   (
                                                       p.ProductCode.Contains(prod.SearchString) ||
                                                       p.ProductName.Contains(prod.SearchString) ||
                                                       prod.SearchString == ""
                                                   ) || prod.SearchString == null
                                                   );

            return(await PagedList <Product> .CreateListAsync(products, prod.PageNumber, prod.PageSize));
        }
        public async Task <IActionResult> GetAllAsync([FromQuery] ProductParams planParams)
        {
            var products = await _unitOfWork.Products.GetAllAsync(planParams);

            if (products.Count == 0)
            {
                return(BadRequest("BadRequest: Products cannot be found"));
            }

            Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalItemsCount, products.TotalPagesCount);

            return(Ok(products));
        }
 public IActionResult GetProductBySize([FromQuery] ProductParams productParams, string line)
 {
     try
     {
         var products     = _repo.GetProductByLine(productParams, line);
         var productsFull = _mapper.Map <IEnumerable <ProductForListDto> >(products);
         Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);
         return(Ok(productsFull));
     }
     catch (Exception ex)
     {
         return(BadRequest("Σφάλμα"));
     }
 }
        public async Task <IActionResult> GetAllProducts([FromQuery] ProductParams productParams)
        {
            var productsFromRepo = await _unitOfWork.Products.GetAllProducts(productParams);

            var productToReturn = _mapper.Map <IEnumerable <ProductForReturnDto> >(productsFromRepo);

            Response.AddPagination(
                productsFromRepo.CurrentPage,
                productsFromRepo.PageSize,
                productsFromRepo.TotalCount,
                productsFromRepo.TotalPages);

            return(Ok(productToReturn));
        }
示例#28
0
        public void IntegrationTest_Given_DefaultProductParams_When_GetProductsForModeration_Then_Return_PagedProducts_WithOkStatus_And_AddDefaultPaginationHeader()
        {
            //Arrange

            var httpContext = new DefaultHttpContext();

            var expected = Data.ProductForModerationDto();

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext
            };

            var sut = new AdminController(_mockedUserManager.Object, _mapper, _cloudinaryConfig, _unitOfWork)
            {
                ControllerContext = controllerContext
            };

            var productParams = new ProductParams();

            //Act
            var result = sut.GetProductsForModeration(productParams).Result;

            var header = sut.Response.Headers["Pagination"];

            var paginationHeader = JsonConvert.DeserializeObject <PaginationHeader>(header.ToString());


            //Assert
            result.Should().BeOfType(typeof(OkObjectResult));

            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(expected);

            result.As <OkObjectResult>().Value.As <List <ProductForModerationDto> >().FirstOrDefault()
            .Should()
            .BeEquivalentTo(expected.FirstOrDefault());

            result.As <OkObjectResult>().Value.As <List <ProductForModerationDto> >().LastOrDefault()
            .Should()
            .BeEquivalentTo(expected.LastOrDefault());

            result.As <OkObjectResult>().Value.As <List <ProductForModerationDto> >().Take(4).ToList()
            .Should()
            .BeEquivalentTo(expected.Take(4).ToList());

            paginationHeader.Should().NotBeNull();
            paginationHeader.CurrentPage.Should().Be(1);
            paginationHeader.ItemsPerPage.Should().Be(10);
        }
        public async Task <IActionResult> GetProducts([FromQuery] ProductParams prodParams)
        {
            try
            {
                if (string.IsNullOrEmpty(prodParams.ProductName))
                {
                    prodParams.ProductName = null;
                }

                if (prodParams.CategoryId == 0)
                {
                    prodParams.CategoryId = 0;
                }

                var products = await _repo.ProductByFilters(prodParams);

                if (products == null)
                {
                    return(NotFound());
                }
                var prodToReturn = _mapper.Map <IEnumerable <ProductListDto> >(products);
                Response.AddPagination(products.CurrentPage, products.PageSize, products.TotalCount, products.TotalPages);
                return(Ok(prodToReturn));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(NoContent());
            }

            /*try
             * {
             *  var query = _repo.GetQueryable();
             *  var products = await _repo.Query(_repo.Include(query, "Category"), pagParams);
             *  if(products == null)
             *  {
             *      return NotFound();
             *  }
             *
             *  var prodToReturn = _mapper.Map<IEnumerable<ProductListDto>>(products);
             *  Response.AddPagination(products.CurrentPage,products.PageSize,products.TotalCount, products.TotalPages);
             *  return Ok(prodToReturn);
             * }
             * catch(Exception e)
             * {
             *  Console.WriteLine(e.Message);
             *  return NoContent();
             * }*/
        }
示例#30
0
        public async Task <ActionResult <PagedList <Product> > > GetProducts([FromQuery] ProductParams productParams)
        {
            var query = _context.Products
                        .Sort(productParams.OrderBy)
                        .Search(productParams.SearchTerm)
                        .Filter(productParams.Brands, productParams.Types)
                        .AsQueryable();

            var products = await PagedList <Product> .ToPagedList(query,
                                                                  productParams.PageNumber, productParams.PageSize);

            Response.AddPaginationHeader(products.MetaData);

            return(products);
        }