Example #1
0
        private IQueryable <Product> FilterProduct(IQueryable <Product> products, GetVAProductsQuery query)
        {
            if (!string.IsNullOrEmpty(query.CategoryId))
            {
                if (query.CategoryType == "main")
                {
                    products = products.Where(x => x.MainCategoryId == query.CategoryId);
                }
                else if (query.CategoryType == "sub")
                {
                    products = products.Where(x => x.SubCategoryId == query.CategoryId);
                }
                else if (query.CategoryType == "tri")
                {
                    products = products.Where(x => x.TertiaryCategoryId == query.CategoryId);
                }
            }

            if (!string.IsNullOrEmpty(query.SearchString))
            {
                products = products.Where(x => EF.Functions.Like(x.Name, $"%{query.SearchString}%"));
            }

            return(products);
        }
Example #2
0
        public IEnumerable <ProductViewModel> Do(GetVAProductsQuery query)
        {
            var discounts = _ctx.AccountUsers
                            .Include(x => x.Account)
                            .ThenInclude(x => x.Discounts)
                            .FirstOrDefault(x => x.UserId == query.UserId && x.Active)?
                            .Account?
                            .Discounts;

            var realProducts       = _ctx.Products.Where(x => x.Published != false).Where(y => y.ValueAddedProduct == true);
            var actualRealProducts = FilterProduct(realProducts, query).ToList();


            if (_discounts.Value.DiscountPercentage > 0)
            {
                var products = actualRealProducts.Select(x => new ProductViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    Price       = GetPrice(x, null),
                    //discounts for dynamic pricing
                    Discount        = discounts?.Any(y => y.ProductId == x.Id) ?? false,
                    DiscountedValue = GetPrice(x, discounts),
                    ImageUrl        = x.ImageUrl,
                    UOM             = x.Unit,
                    Colour          = x.Colour,
                    Code            = x.ExternalId,
                    ValueAdded      = x.ValueAddedProduct
                });

                foreach (var x in products)
                {
                    if (x.Discount != true)
                    {
                        // x.ThresholdDiscountedPrice = Convert.ToDecimal(x.Price) * _discounts.Value.DiscountPercentage;
                    }
                }
                return(products);
            }
            else
            {
                var products = actualRealProducts.Select(x => new ProductViewModel
                {
                    Id          = x.Id,
                    Name        = x.Name,
                    Description = x.Description,
                    Price       = GetPrice(x, null),
                    //discounts for dynamic pricing
                    Discount        = discounts?.Any(y => y.ProductId == x.Id) ?? false,
                    DiscountedValue = GetPrice(x, discounts),
                    ImageUrl        = x.ImageUrl,
                    UOM             = x.Unit,
                    Colour          = x.Colour,
                    Code            = x.ExternalId,
                    ValueAdded      = x.ValueAddedProduct,
                    OutOfStock      = x.OutOfStock
                });


                return(products);
            }

            //return products;
        }