public async Task <IActionResult> Create([Bind("Category_id,Item_name,Item_price,Quantity,DateTime")] Add_item add_item) { if (ModelState.IsValid) { _context.Add(add_item); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); } //var combineList = _context.Add_item.Include("category").ToList(); //ViewBag.itemlist = combineList; List <Add_item> ListOfItems = _context.Add_item.ToList(); List <Item_category> categorys = _context.Items_category.ToList(); List <JoinCategoryAndItem> joinList = new List <JoinCategoryAndItem>(); var results = (from pd in categorys join od in ListOfItems on pd.IDT equals od.Category_id select new { pd.Category_name, od.Item_price, pd.ImageURL, od.Item_name, od.Quantity, od.id, }).ToList(); foreach (var item in results) { JoinCategoryAndItem JoinObject = new JoinCategoryAndItem(); JoinObject.Category_name = item.Category_name; JoinObject.Item_price = item.Item_price; JoinObject.ImageURL = item.ImageURL; JoinObject.Quantity = item.Quantity; JoinObject.Item_name = item.Item_name; JoinObject.id = item.id; joinList.Add(JoinObject); var JoinListToViewbag = joinList.ToList(); ViewBag.JoinList = JoinListToViewbag; } BindCategoryName(); return(View()); }
public IActionResult Dashboard() { var combineList = _context.Add_item.ToList(); ViewBag.itemlist = combineList; List <Add_item> ListOfItems = _context.Add_item.ToList(); List <Item_category> categorys = _context.Items_category.ToList(); List <JoinCategoryAndItem> joinList = new List <JoinCategoryAndItem>(); var categoryCount = _context.Items_category.Count(); var ItemCount = _context.Add_item.Sum(i => i.Quantity); ViewBag.categoryCount = categoryCount; ViewBag.Itemcount = ItemCount; var results = (from pd in categorys join od in ListOfItems on pd.IDT equals od.Category_id select new { pd.Category_name, od.Item_price, pd.ImageURL, od.Item_name, od.Quantity, od.id, }).ToList(); foreach (var item in results) { JoinCategoryAndItem JoinObject = new JoinCategoryAndItem(); JoinObject.Category_name = item.Category_name; JoinObject.Item_price = item.Item_price; JoinObject.ImageURL = item.ImageURL; JoinObject.Quantity = item.Quantity; JoinObject.Item_name = item.Item_name; JoinObject.id = item.id; joinList.Add(JoinObject); var JoinListToViewbag = joinList.ToList(); ViewBag.JoinList = JoinListToViewbag; } return(View()); }
public void bindSubmitItems() { string currentDate = DateTime.Now.ToString("yyyy-MM-dd"); //ViewBag.d = currentDate; List <Add_item> ListOfItems = _context.Add_item.ToList(); List <Item_category> categorys = _context.Items_category.ToList(); List <JoinCategoryAndItem> joinList = new List <JoinCategoryAndItem>(); var results = (from pd in categorys join od in ListOfItems on pd.IDT equals od.Category_id where od.DateTime != currentDate && od.Quantity > 0 select new { pd.Category_name, od.Item_price, pd.ImageURL, od.Item_name, od.Quantity, od.id, }).ToList(); foreach (var item in results) { JoinCategoryAndItem JoinObject = new JoinCategoryAndItem(); JoinObject.Category_name = item.Category_name; JoinObject.Item_price = item.Item_price; JoinObject.ImageURL = item.ImageURL; JoinObject.Quantity = item.Quantity; JoinObject.Item_name = item.Item_name; JoinObject.id = item.id; joinList.Add(JoinObject); var JoinListToViewbag = joinList.ToList(); ViewData["SearchStatus"] = search; ViewBag.JoinList = JoinListToViewbag; } }
public List <JoinCategoryAndItem> joinLists(string Value) { List <Add_item> ListOfItems = _context.Add_item.ToList(); List <Item_category> categorys = _context.Items_category.ToList(); List <JoinCategoryAndItem> joinList = new List <JoinCategoryAndItem>(); List <JoinCategoryAndItem> joinList1 = new List <JoinCategoryAndItem>(); var results = (from pd in categorys join od in ListOfItems on pd.IDT equals od.Category_id select new { pd.Category_name, od.Item_price, pd.ImageURL, od.Item_name, od.Quantity, od.id, }).ToList(); foreach (var item in results) { JoinCategoryAndItem JoinObject = new JoinCategoryAndItem(); JoinObject.Category_name = item.Category_name; JoinObject.Item_price = item.Item_price; JoinObject.ImageURL = item.ImageURL; JoinObject.Quantity = item.Quantity; JoinObject.Item_name = item.Item_name; JoinObject.id = item.id; joinList.Add(JoinObject); var joinedToList = joinList.ToList(); var searchResults1 = joinedToList.Where(data => data.Item_name.Contains(Value.ToLower()) || data.Item_name.Contains(Value.ToUpper()) || data.Category_name.Contains(Value.ToUpper())); joinList1 = searchResults1.ToList(); } return(joinList1); }
public IActionResult Create(Item_category cateGory, [Optional] string Value) { var combineList = _context.Add_item.ToList(); ViewBag.itemlist = combineList; List <Add_item> ListOfItems = _context.Add_item.ToList(); List <Item_category> categorys = _context.Items_category.ToList(); List <JoinCategoryAndItem> joinList = new List <JoinCategoryAndItem>(); var results = (from pd in categorys join od in ListOfItems on pd.IDT equals od.Category_id select new { pd.Category_name, od.Item_price, pd.ImageURL, od.Item_name, od.Quantity, od.id, }).ToList(); foreach (var item in results) { JoinCategoryAndItem JoinObject = new JoinCategoryAndItem(); JoinObject.Category_name = item.Category_name; JoinObject.Item_price = item.Item_price; JoinObject.ImageURL = item.ImageURL; JoinObject.Quantity = item.Quantity; JoinObject.Item_name = item.Item_name; JoinObject.id = item.id; joinList.Add(JoinObject); var JoinListToViewbag = joinList.ToList(); ViewData["SearchStatus"] = search; if (Value == null) { ViewBag.JoinList = JoinListToViewbag; } else { //LETS COUNT THE RESULTS int counts = joinLists(Value).Count(); if (counts > 0) { ViewBag.JoinList = joinLists(Value); ViewBag.ItemsCount = counts; ViewBag.SearchValue = Value; } else { ViewBag.JoinList = null; ViewBag.ItemsCount = 0; ViewBag.SearchValue = Value; } } } BindCategoryName(); return(View()); }