public ActionResult AddMenuToCart(int id) { Cart cart = new Cart(); cart.UsersId = Convert.ToInt32(Session["UserId"]); var getFoodId = MenuRepo.GetMenu(id); var getCart = CartRepo.GetCart(id); if (getCart != null) { getCart.Quantity += 1; getCart.TotalAmount = getCart.Quantity * getFoodId.Price; CartRepo.UpdateCart(getCart); ViewBag.Success = "Added Successfully"; return(Json(JsonRequestBehavior.AllowGet)); } else { cart.MenusId = id; cart.Price = getFoodId.Price; cart.Quantity = 1; cart.TotalAmount = getFoodId.Price * cart.Quantity; cart.FoodName = getFoodId.FoodName; CartRepo.AddCart(cart); ViewBag.Success = "Added Successfully"; return(Json(JsonRequestBehavior.AllowGet)); } }
public void getItemsInCart(Customer activeCustomer) { START: Console.Clear(); _consoleHelper.WriteHeaderToConsole("Items in Cart"); char spacePad = ' '; _consoleHelper.WriteLine("Product Qty Unit Price Total "); Console.ForegroundColor = ConsoleColor.DarkCyan; _consoleHelper.WriteLine("*********************************************************"); Console.ForegroundColor = ConsoleColor.White; var cartItems = cartDetail.GetItemsInCart(activeCustomer.CustomerId); foreach (var item in cartItems) { _consoleHelper.WriteLine(item.ProductName.PadRight(23, spacePad).Substring(0, 23) + item.ProductQuantity.ToString().PadRight(8, spacePad).Substring(0, 8) + '$' + item.ProductPrice.ToString().Remove(item.ProductPrice.ToString().Length - 2).PadLeft(7, spacePad).PadRight(13, spacePad).Substring(0, 13) + '$' + item.Total.ToString().Remove(item.ProductPrice.ToString().Length - 2).PadLeft(7, spacePad)); } var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); if (activeCart == null) { cartRepo.AddCart(activeCustomer.CustomerId); activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); } Console.ForegroundColor = ConsoleColor.DarkCyan; _consoleHelper.WriteLine("*********************************************************"); Console.ForegroundColor = ConsoleColor.White; string cartTotalLine = $"Total: ({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}"; string space = new string(' ', (56 - cartTotalLine.Length)); _consoleHelper.WriteLine(space + cartTotalLine); string[] menuOptions = new string[] { "Checkout", "Empty Cart" }; int counter = 1; foreach (var option in menuOptions) { _consoleHelper.WriteLine($"{counter}. {option} "); counter++; } _consoleHelper.WriteExitCommand(); var selection = _consoleHelper.WriteAndReadFromConsole("> "); if (!(selection.Equals(""))) { if (_consoleHelper.CheckForUserExit(selection)) { return; } ; if (selection.Equals("1")) { (new CartController()).checkout(activeCustomer); } else if (selection.Equals("2")) { cartRepo.EmptyCart(activeCustomer.CustomerId); _consoleHelper.WriteLine("Cart has been emptied!"); Thread.Sleep(2000); return; } else { _consoleHelper.WriteLine("Invalid option selected"); Thread.Sleep(2000); Console.Clear(); goto START; } } else { _consoleHelper.WriteLine("Invalid option selected"); Thread.Sleep(2000); Console.Clear(); goto START; } }
public ActionResult OrderFood(int menuId) { cartRep.AddCart(IdData.UserId, menuId, IdData.TableId); Session["OrderFood"] = "Added to Cart"; return(RedirectToAction("FoodMenu")); }
public void Create(AddCartCommand newCart) { var repo = new CartRepository(); repo.AddCart(newCart); }
public CartModelClass AddCart(CartModelClass whis) { return(cart.AddCart(whis)); }
static void Main(string[] args) { SplashScreen splash = new SplashScreen(); splash.GenerateSplashScreen(); Console.SetWindowSize(57, 35); Customer activeCustomer = null; ConsoleHelper consoleHelper = new ConsoleHelper(); SHOWMENU: { Console.Clear(); consoleHelper.WriteHeaderToConsole("Welcome to Bangazon!"); if (activeCustomer != null) { string custString = $"Logged In As: {activeCustomer.CustomerName}"; string cartString = ""; var cartRepo = new CartRepository(); var activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); if (activeCart == null) { cartRepo.AddCart(activeCustomer.CustomerId); activeCart = cartRepo.GetActiveCart(activeCustomer.CustomerId); } else { var cartDetail = new CartDetailRepository(); cartString = $"Cart({cartDetail.GetTotalItemsInCart(activeCart.CartId)}) {cartDetail.GetCartPrice(activeCart.CartId)}"; } string space = new string(' ', (56 - cartString.Length - custString.Length)); if (cartString.Length < 1) { consoleHelper.WriteLine($"{custString}\n"); } else { consoleHelper.WriteLine($"{custString}{space}{cartString}\n"); } } consoleHelper.WriteLine( "1.Create a new customer account" + "\n" + "2.Choose an existing customer" + "\n" + "3.Create a new payment option" + "\n" + "4.Add product(s) to shopping cart" + "\n" + "5.View Items in Cart\n" + "6.Complete an order" + "\n" + "7.View product popularity" + "\n" + "8.Logout Current User" + "\n" + "9.Leave Bangazon!"); Console.ForegroundColor = ConsoleColor.White; var userInput = consoleHelper.WriteAndReadFromConsole("> "); switch (userInput) { case "1": Console.Clear(); var CustomerInfo = new CustomerController(); activeCustomer = CustomerInfo.CreateCustomer(); goto SHOWMENU; case "2": Console.Clear(); var selectCustomerCtrl = new SelectCustomerController(); activeCustomer = selectCustomerCtrl.SelectActiveCustomer(); break; case "3": if (activeCustomer == null) { Console.Clear(); selectCustomerCtrl = new SelectCustomerController(); activeCustomer = selectCustomerCtrl.SelectActiveCustomer(); if (activeCustomer == null) { break; } } Console.Clear(); var PaymentCtrl = new PaymentController(); PaymentCtrl.RequestPayment(activeCustomer); break; case "4": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new CartController()).addProduct(activeCustomer); break; case "5": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new ViewCartController()).getItemsInCart(activeCustomer); break; case "6": if (activeCustomer == null) { Console.Clear(); activeCustomer = (new SelectCustomerController()).SelectActiveCustomer(); if (activeCustomer == null) { break; } } (new CartController()).checkout(activeCustomer); break; case "7": Console.Clear(); var productPopularityController = new ProductPopularityController(); productPopularityController.DisplayPopularProducts(); break; case "8": if (activeCustomer != null) { consoleHelper.WriteLine($"\nUser {activeCustomer.CustomerName} is being logged out!"); activeCustomer = null; Thread.Sleep(1500); } else { consoleHelper.WriteLine($"\nNo customer currently logged in!"); Thread.Sleep(1500); } break; case "9": Console.Clear(); consoleHelper.WriteHeaderToConsole("Logging out..."); Thread.Sleep(1500); Environment.Exit(0); break; default: consoleHelper.WriteLine("please select a valid menu item..."); Thread.Sleep(1000); break; } goto SHOWMENU; } }