Example #1
0
        public void AddToCart(string menuItemName)
        {
            truYumContext context = new truYumContext();
            var           Query   = from mentItem in context.MenuItems.Include(m => m.Category)
                                    where mentItem.Name == menuItemName
                                    select mentItem;

            if (Query == null)
            {
                Console.WriteLine("Incorrect menu item.Please check");
                return;
            }
            foreach (var item in Query.ToList())
            {
                Console.WriteLine("{0} {1} {2} {3} {4}", item.Name, item.Price.ToString(), item.Category.Name,
                                  item.dateOfLaunch.ToString(), item.Active.ToString(), item.freeDelivery.ToString());


                Boolean myparameter = true;
                while (myparameter)
                {
                    if (item.Name == null)
                    {
                        Console.WriteLine("Incorrect menu item.  Please check");
                    }
                    else
                    {
                        Console.WriteLine("Enter Price to Check");
                        double myprice = double.Parse(Console.ReadLine());
                        Console.WriteLine("Enter categoryId to Check");
                        string categoryName = Console.ReadLine();

                        if ((item.Price == myprice) && (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);


                            myparameter = false;

                            context.SaveChanges();
                            Console.WriteLine("Menu item added to cart successfully");
                        }
                        else
                        {
                            Console.WriteLine("Incorrect menu item name. Please reenter");
                        }
                    }
                }
            }
        }
        public void EditMenuItem(string menuItemName)
        {
            truYumContext context = new truYumContext();
            var           Query   = from mentItem in context.MenuItems.Include(m => m.Category)
                                    where mentItem.Name == menuItemName
                                    select mentItem;

            if (Query == null)
            {
                Console.WriteLine("Incorrect menu item.Please check");
                return;
            }

            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 myparameter = true;
                while (myparameter)
                {
                    if (item.Name == null)
                    {
                        Console.WriteLine("Incorrect menu item.  Please check");
                    }
                    else
                    {
                        Console.WriteLine("Enter Price to Check");
                        double myprice = double.Parse(Console.ReadLine());
                        Console.WriteLine("Enter categoryId to Check");
                        string categoryName = Console.ReadLine();
                        if ((item.Price == myprice) && (item.Category.Name == categoryName))
                        {
                            Console.WriteLine("All data is correct");
                            Console.WriteLine("Enter price to Change");
                            double newprice = double.Parse(Console.ReadLine());
                            item.Price  = newprice;
                            myparameter = false;
                            Console.WriteLine("Data is saved. Here is the updated data");
                            context.SaveChanges();
                        }
                        else
                        {
                            Console.WriteLine("Incorrect category. Please reenter data");
                        }
                    }
                }
            }
        }
Example #3
0
        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();
        }
Example #4
0
        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;
            }
            foreach (var item in Query.ToList())
            {
                if (item.MenuItem.Name == menuItemName)
                {
                    context.Carts.Remove(item);
                    context.SaveChanges();
                    Console.WriteLine("Menu item removed from cart successfully");
                }
            }
        }