示例#1
0
 public void SearchCategoryTest()
 {
     l1.AddLast(white_bread);
     l1.AddLast(black_bread);
     l1.AddLast(cutted_bread);
     Assert.AreEqual(FilterProducts.Filter("bread", l1, "byCategory"), l1);
 }
示例#2
0
        public async Task <IActionResult> Filter(FilterProducts filterProducts)
        {
            if (filterProducts.CategoryId != -1 && filterProducts.SupplierId != -1)
            {
                var products = from product in _context.Products
                               where product.CategoryId == filterProducts.CategoryId && product.SupplierId == filterProducts.SupplierId
                               select product;
                filterProducts.productsList = await products.ToListAsync();
            }
            else
            {
                filterProducts.productsList = await _context.Products.ToListAsync();
            }
            var categories = await _context.Categories.ToListAsync();

            Categories category = new Categories();

            category.CategoryId   = -1;
            category.CategoryName = "Select Category";
            categories.Insert(0, category);
            ViewData["CategoryId"] = new SelectList(categories, "CategoryId", "CategoryName");
            var suppliers = await _context.Suppliers.ToListAsync();

            Suppliers supplier = new Suppliers();

            supplier.SupplierId  = -1;
            supplier.CompanyName = "Select Company";
            suppliers.Insert(0, supplier);
            ViewData["SupplierId"] = new SelectList(suppliers, "SupplierId", "CompanyName");
            return(View("~/Views/Products/Index.cshtml", filterProducts));
        }
示例#3
0
        // GET: Products
        public async Task <IActionResult> Index()
        {
            FilterProducts filterProducts = new FilterProducts();

            filterProducts.productsList = await _context.Products.ToListAsync();

            var categories = await _context.Categories.ToListAsync();

            Categories category = new Categories();

            category.CategoryId   = -1;
            category.CategoryName = "Select Category";
            categories.Insert(0, category);
            ViewData["CategoryId"] = new SelectList(categories, "CategoryId", "CategoryName", "Select Category");
            var suppliers = await _context.Suppliers.ToListAsync();

            Suppliers supplier = new Suppliers();

            supplier.SupplierId  = -1;
            supplier.CompanyName = "Select Company";
            suppliers.Insert(0, supplier);
            ViewData["SupplierId"]    = new SelectList(suppliers, "SupplierId", "CompanyName", "Select Supplier");
            filterProducts.CategoryId = -1;
            filterProducts.SupplierId = -1;
            return(View(filterProducts));
        }
示例#4
0
        public IList <Product> GetList()
        {
            FilterProducts filter = new FilterProducts();

            return(GetList(filter));
        }
示例#5
0
 public void SearchNoResultsTest()
 {
     Assert.AreEqual(FilterProducts.Filter("chocko", SearchProducts.Search("bread"), "byName"), l1);
 }
示例#6
0
 public void SearchBlackBreadTest()
 {
     l1.AddLast(black_bread);
     Assert.AreEqual(FilterProducts.Filter("black bread", SearchProducts.Search("bread"), "byName"), l1);
 }
示例#7
0
 public void SearchWhiteBreadTest()
 {
     l1.AddLast(white_bread);
     Assert.AreEqual(FilterProducts.Filter("white bread", SearchProducts.Search("bread"), "byName"), l1);
 }