public void RemoveFromCart(string menuItemName) { TruYumContext context = new TruYumContext(); var query = from cart in context.Carts.Include(m => m.MenuItem) where cart.MenuItem.Name == menuItemName select cart; if (query == null) { Console.WriteLine("No item in cart for the user"); return; } else { foreach (var item in query.ToList()) { Boolean removeparameter = true; while (removeparameter) { if (item.MenuItem.Name == menuItemName) { context.Carts.Remove(item); context.SaveChanges(); Console.WriteLine("Menu item removed from cart successfully"); removeparameter = false; } else { Console.WriteLine("Incorrect menu item name.Please reenter"); return; } } } } }
public void AddToCart(string menuItemName) { TruYumContext context = new TruYumContext(); var query = from menuitem in context.MenuItems.Include(m => m.Category) where menuitem.Name == menuItemName select menuitem; if (query == null) { Console.WriteLine("No Records are fetched"); return; } else { foreach (var item in query.ToList()) { Console.WriteLine("{0} {1} {2} {3} {4}", item.Name, item.Price.ToString(), item.dateOfLaunch.ToString(), item.Active.ToString(), item.freeDelivery.ToString()); Boolean addparmeter = true; while (addparmeter) { if (item.Name == " " || item.Name == null) { Console.WriteLine("Incorrect menuItem .Please Check"); return; } else { Console.WriteLine("Enter a price to add"); double price = double.Parse(Console.ReadLine()); Console.WriteLine("Enter a categoryName to Check"); string categoryName = Console.ReadLine(); if ((item.Price == price) && (item.Category.Name == categoryName)) { int userId = 1; Cart c = new Cart(); c.userId = userId; c.menuItemId = item.Id; c.MenuItem = item; context.Carts.Add(c); addparmeter = false; context.SaveChanges(); Console.WriteLine("Menu item added to cart successfully"); } else { Console.WriteLine("Incorrect menu item name.Please reenter"); return; } } } } } }
public void EditMenuItem(string menuItemName) { TruYumContext context = new TruYumContext(); var query = from menuItem in context.MenuItems where menuItem.Name == menuItemName select menuItem; if (query == null) { Console.WriteLine("Incorrect menu item.Please check"); return; } else { foreach (var item in query.ToList()) { Console.WriteLine("{0} {1} {2}", item.Name, item.Price.ToString(), item.Category.Name.ToString()); Boolean editparameter = true; while (editparameter) { if (item.Name == null || item.Name == " ") { Console.WriteLine("Incorrect name.Please provide valid name"); return; } else { Console.WriteLine("Enter a price to check"); double price = double.Parse(Console.ReadLine()); Console.WriteLine("Enter a Category to check"); string category = Console.ReadLine(); if (item.Price == price && item.Category.Name == category) { Console.WriteLine("All Data is Correct"); Console.WriteLine("Enter the Price To change"); double price2 = double.Parse(Console.ReadLine()); item.Price = price2; editparameter = false; Console.WriteLine("Data is saved .Here is the Updated data"); context.SaveChanges(); ViewMenuItemListAdmin v = new ViewMenuItemListAdmin(); v.ViewMenuItemAdmin(); } else { Console.WriteLine("Incorrect category. Please reenter data"); } } } } } }
public void AddMenuItem(string name, string category, double price, Boolean isActive, DateTime dateOfLaunch, Boolean freeDelivery) { TruYumContext context = new TruYumContext(); MenuItem menuItem = new MenuItem(); menuItem.Name = name; menuItem.freeDelivery = freeDelivery; menuItem.Price = price; menuItem.Active = isActive; menuItem.dateOfLaunch = dateOfLaunch; int categoryId = context.Categories.Where(iter => iter.Name.Equals(category, StringComparison.OrdinalIgnoreCase)).Select(iter => iter.Id).FirstOrDefault(); menuItem.categoryId = categoryId; context.MenuItems.Add(menuItem); context.SaveChanges(); Console.WriteLine("item added successfully"); }
public void ViewMenuItemAdmin() { TruYumContext context = new TruYumContext(); var query = from menuitem in context.MenuItems select new { menuitem.Name, menuitem.Price, menuitem.Category, menuitem.dateOfLaunch, menuitem.Active, menuitem.freeDelivery }; foreach (var item in query.ToList()) { Console.WriteLine("{0} {1} {2} {3} {4}", item.Name, item.Price.ToString(), item.dateOfLaunch.ToString(), item.Active.ToString(), item.freeDelivery.ToString()); } }
public void ViewCartItems() { TruYumContext context = new TruYumContext(); var Query = from cart in context.Carts.Include(m => m.MenuItem) where cart.userId == 1 select cart; if (Query == null) { Console.WriteLine("No Items in Cart"); return; } else { foreach (var item in Query.ToList()) { Console.WriteLine("{0} {1}", item.userId, item.MenuItem.Name); } } }