예제 #1
0
        /// <summary>
        /// Performs a search for products using the supplied search parameters and returns a list of Product objects
        /// </summary>
        /// <param name="searchParameters">The product search parameters.</param>
        /// <returns></returns>
        public List <Product> ProductSearch(DTO.ProductSearchParameters searchParameters)
        {
            IQueryable <Product> Products;

            //Get all products first
            Products = _context.Products;

            //If brand ID's provided then add these to the where clause
            if (searchParameters.BrandIds.Count() > 0)
            {
                Products = Products.Where(x => searchParameters.BrandIds.Any(i => i == x.BrandId));
            }

            //If size ID's provided then add these to the where clause
            if (searchParameters.SizeIds.Count() > 0)
            {
                Products = Products.Where(x => searchParameters.SizeIds.Any(i => i == x.SizeId));
            }

            //If colour ID's provided then add these to the where clause
            if (searchParameters.ColourIds.Count() > 0)
            {
                Products = Products.Where(x => searchParameters.ColourIds.Any(i => i == x.ColourId));
            }

            if (!String.IsNullOrEmpty(searchParameters.SearchString))
            {
                Products = SearchForProductsViaString(searchParameters.SearchString, Products);
            }

            return(Products.ToList());
        }
예제 #2
0
        /// <summary>
        /// Performs a search for products using the supplied search parameters and returns a list of Product objects
        /// The DiscountedSellPrice for the products is calculated based on the DiscountGroup associated with the
        /// specified customer
        /// </summary>
        /// <param name="customerId">The customer id.</param>
        /// <param name="searchParameters">The product search parameters.</param>
        /// <returns></returns>
        public List <Product> CustomerProductSearch(int customerId, DTO.ProductSearchParameters searchParameters)
        {
            List <Product> Products;

            //Perform search on products
            Products = ProductSearch(searchParameters);
            //Lookup customer that has been provided
            Customer _Customer = _context.Customers.Include("DiscountGroup").Where(c => c.CustomerId == customerId).FirstOrDefault();

            if (_Customer != null)
            {
                //We have found a customer so lets update the discount price
                foreach (Product p in Products)
                {
                    p.DiscountedSellPrice = CalculateDiscountedPrice((decimal)_Customer.DiscountGroup.DiscountPercentage, p.SellPrice, p.CostPrice);
                }
            }

            return(Products);
        }