Esempio n. 1
0
        public void RemoveFromCart(string menuItemName)
        {
            var context = new truYumContext();
            var query   = context.Carts.Include("MenuItem").Where(iter => iter.UserId == 1).ToList();

            if (query == null)
            {
                Console.WriteLine("No item in cart for the user");
            }
            else
            {
                bool datacorrectness = true;
                int  f = 0;
                while (datacorrectness)
                {
                    foreach (var cart in query)
                    {
                        if (cart.menuItem.Name == menuItemName)
                        {
                            context.Carts.Remove(cart);
                            Console.WriteLine("Menu Item removed from cart successfully");
                            datacorrectness = false;
                            f = 1;
                        }
                    }
                    if (f == 0)
                    {
                        Console.WriteLine("Incorrect menu item name Please reenter");
                    }
                }
            }
            context.SaveChanges();
        }
Esempio n. 2
0
        public void AddToCart(string menuItemName)
        {
            var  context         = new truYumContext();
            var  query           = from menu in context.MenuItems where menu.Name == menuItemName select menu;
            bool datacorrectness = true;

            while (datacorrectness)
            {
                if (query == null)
                {
                    Console.WriteLine("Incorrect menu item name.Please reenter");
                    datacorrectness = false;
                }
                else
                {
                    int  userId = 1;
                    Cart c      = new Cart();
                    c.UserId     = userId;
                    c.MenuItemId = query.First().Id;
                    context.Carts.Add(c);
                    context.SaveChanges();

                    Console.WriteLine("Menu item added to cart successfully");
                    Console.WriteLine("Do you want to continue adding to cart[Y|N]");
                    char ch = char.Parse(Console.ReadLine());
                    if (ch == 'N')
                    {
                        datacorrectness = false;
                        break;
                    }
                    Console.WriteLine("Enter the name of the item to add into cart");
                    AddToCart(Console.ReadLine());
                }
            }
        }
Esempio n. 3
0
        public void EditMenuItem(string menuItemName)
        {
            var context = new truYumContext();
            var query   = from menu in context.MenuItems where menu.Name == menuItemName select menu;

            if (query == null)
            {
                Console.WriteLine("Incorrect menu item.please check\n");
            }
            else
            {
                bool datacorrectness = true;
                while (datacorrectness)
                {
                    if (query == null || query.First().Name == " ")
                    {
                        Console.WriteLine("Incorrect name.Please provide valid name");
                        menuItemName    = Console.ReadLine();
                        datacorrectness = false;
                        break;
                    }
                    else
                    {
                        var cat = from category in context.Categories where category.Name == query.First().category.Name select category;
                        if (cat == null)
                        {
                            Console.WriteLine("Incorrect category.Please reenter data");
                            datacorrectness = false;
                        }
                        else
                        {
                            Console.WriteLine("All data is correct");
                            Console.WriteLine("Enter price to edit");
                            query.First().Price = double.Parse(Console.ReadLine());
                            datacorrectness = false;
                            context.MenuItems.AddOrUpdate();
                            context.SaveChanges();
                            Console.WriteLine("Data is saved,Here is the updated data");
                            ViewMenuItemListAdmin viewdata = new ViewMenuItemListAdmin();
                            viewdata.ViewMenuItemAdmin();
                        }
                    }
                }
            }
        }
        public void AddMenuItem(string name, string category, double price, Boolean isActive, DateTime dateOfLaunch, Boolean freeDelivery)
        {
            var      context    = new truYumContext();
            int      categoryId = context.Categories.Where(iter => iter.Name.Equals(category, StringComparison.OrdinalIgnoreCase)).Select(iter => iter.Id).FirstOrDefault();
            MenuItem menuItem   = new MenuItem();

            menuItem.Name         = name;
            menuItem.Price        = price;
            menuItem.Active       = isActive;
            menuItem.DateOflaunch = dateOfLaunch;
            menuItem.FreeDelivery = freeDelivery;
            if (!Convert.ToBoolean(categoryId))
            {
                Console.WriteLine("\nCategory does not exist");
            }
            else
            {
                menuItem.CategoryId = categoryId;

                context.MenuItems.Add(menuItem);
                Console.WriteLine("\nAdded Successfully");
                context.SaveChanges();
            }
        }