public void OrderItemsCatalog(string orderBy) { ShopModel model = (ShopModel)Session["model"]; ItemCatalogFacilitator.ItemSorttype type = ItemCatalogFacilitator.ItemSorttype.NAME_AZ; switch (orderBy) { case "PRICE_HL": type = ItemCatalogFacilitator.ItemSorttype.PRICE_HL; break; case "PRICE_LH": type = ItemCatalogFacilitator.ItemSorttype.PRICE_LH; break; case "NAME_AZ": type = ItemCatalogFacilitator.ItemSorttype.NAME_AZ; break; case "NAME_ZA": type = ItemCatalogFacilitator.ItemSorttype.NAME_ZA; break; } model.itemCatalog = ItemCatalogFacilitator.OrderItems(type, model.itemCatalog); Session["model"] = model; }
/// <summary> /// Loads the main Index view. /// /// Creates a new model and loads the item catalog from the database. /// </summary> /// <returns></returns> public ActionResult Index() { Session["fromSearch"] = false; //model= TestDataGenerator.PopulateDummyModel(); model = new ShopModel(); model.itemCatalog = ItemCatalogFacilitator.GetAllItems(); Session["model"] = model; return(View()); }
public void SearchItems(string searchTerm) { ShopModel model = (ShopModel)Session["model"]; Session["searchTerm"] = searchTerm; model.itemCatalog = ItemCatalogFacilitator.GetAllItems(); // reset model.itemCatalog = ItemCatalogFacilitator.SearchItems(searchTerm, model.itemCatalog); Session["fromSearch"] = true; Session["model"] = model; }
public void SearchItemsTest() { List <Item> itemList = new List <Item>(); Item item1 = new Item { itemID = 1, name = "A", category = "hello", description = "bad no", sellingPrice = 25 }; Item item2 = new Item { itemID = 2, name = "B", category = "djdjd", description = "bad good fire", sellingPrice = 10 }; Item item3 = new Item { itemID = 3, name = "C", category = "category", description = "hello good fire", sellingPrice = 100 }; itemList.Add(item1); itemList.Add(item2); itemList.Add(item3); // going to search for word "hello" itemList = ItemCatalogFacilitator.SearchItems("hello", itemList); // item list should only have 2 items now if (itemList.Count != 2) { Assert.Fail(); } // item list shouldn't contain item2 if (itemList.Contains(item2)) { Assert.Fail(); } }
public void FilterItemsByCategory(string categories) { ShopModel model = (ShopModel)Session["model"]; model.itemCatalog = ItemCatalogFacilitator.GetAllItems(); List <string> catList = new List <string>(); string[] cat = categories.Split(','); for (int i = 0; i < cat.Length; i++) { catList.Add(cat[i]); } model.itemCatalog = ItemCatalogFacilitator.FilterItemsByCategory(catList, model.itemCatalog); Session["model"] = model; }
public void FilterItemsByCategoryTest() { List <Item> itemList = new List <Item>(); Item item1 = new Item { itemID = 1, name = "Item1", category = "Category1", sellingPrice = 50 }; Item item2 = new Item { itemID = 2, name = "Item2", category = "Category2", sellingPrice = 50 }; Item item3 = new Item { itemID = 3, name = "Item3", category = "Category1", sellingPrice = 50 }; itemList.Add(item1); itemList.Add(item2); itemList.Add(item3); List <String> categories = new List <string>(); categories.Add("Category1"); itemList = ItemCatalogFacilitator.FilterItemsByCategory(categories, itemList); // should have 2 items in the list and they should be item1 and item 3 if (itemList.Count != 2) { Assert.Fail(); } if (!(itemList.Contains(item1) && itemList.Contains(item3))) { Assert.Fail(); } }
public void OrderItemsTest() { // create dummy items List <Item> itemList = new List <Item>(); Item item1 = new Item { itemID = 1, name = "A", sellingPrice = 25 }; Item item2 = new Item { itemID = 2, name = "B", sellingPrice = 10 }; Item item3 = new Item { itemID = 3, name = "C", sellingPrice = 100 }; itemList.Add(item1); itemList.Add(item2); itemList.Add(item3); itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.NAME_AZ, itemList); // should be in alphabetical order from A - Z if (itemList[0].name != "A") { Assert.Fail(); } if (itemList[1].name != "B") { Assert.Fail(); } if (itemList[2].name != "C") { Assert.Fail(); } // now check alphabetical order Z-A itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.NAME_ZA, itemList); if (itemList[0].name != "C") { Assert.Fail(); } if (itemList[1].name != "B") { Assert.Fail(); } if (itemList[2].name != "A") { Assert.Fail(); } // now check price Low - High itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.PRICE_LH, itemList); // should be in order item2, item1, item3 if (itemList[0] != item2) { Assert.Fail(); } if (itemList[1] != item1) { Assert.Fail(); } if (itemList[2] != item3) { Assert.Fail(); } // now check price High - Low itemList = ItemCatalogFacilitator.OrderItems(ItemCatalogFacilitator.ItemSorttype.PRICE_HL, itemList); // should be in order item3, item1, item2 if (itemList[0] != item3) { Assert.Fail(); } if (itemList[1] != item1) { Assert.Fail(); } if (itemList[2] != item2) { Assert.Fail(); } }