public ActionResult LogOff() { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); cart.DestroyInstance(); Session.Clear(); return(RedirectToAction("Index", "Home")); }
public ActionResult CheckoutView(string isUser) { if (isUser != null) { UserModel userModel = new UserModel(); return(PartialView("_UserView", userModel)); } else { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); return(PartialView("_ProductView", cart)); } }
public ActionResult ShoppingCartView(string name) { if (name != null) { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); cart.TotalPrice = cart.TotalPrice - cart.ProductsList[name].Price; cart.ProductsList.Remove(name); return(View(cart)); } else { //Save shopping cart code ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); int accountID = Int32.Parse(Session["CurrentID"].ToString()); Order order = Order.ExecuteCreate(accountID, 1, 1, cart.TotalPrice); decimal subtotal = 0; bool isPresent = false; List <Order> orderList = Order.ListByAccountID(accountID); order.Insert(); foreach (Order o in orderList) { List <OrderItem> orderItemList = OrderItem.ListByOrderID(o.ID); foreach (OrderItem item in orderItemList) { item.Delete(); } } foreach (string key in cart.ProductsList.Keys) { Product product = cart.ProductsList[key]; subtotal = subtotal + product.Price; OrderItem orderItem = OrderItem.ExecuteCreate(order.ID, product.ID, 1, product.Price, subtotal); if (!isPresent) { orderItem.Insert(); } } return(View(cart)); } }
public ActionResult ProductList(string idField) { int id = Int32.Parse(idField); ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); Product productToBeUpdated = Product.ExecuteCreate(id); int newQuantity = productToBeUpdated.Status + 1; int idfield = Int32.Parse(idField); Product product = Product.ExecuteCreate(productToBeUpdated.CategoryID, productToBeUpdated.Name, productToBeUpdated.Description, productToBeUpdated.Price, productToBeUpdated.ImageName, newQuantity, productToBeUpdated.CreatedAccountID, productToBeUpdated.ModifiedAccountID); cart.AddProductToCart(id); product.Update(idfield, product); return(PartialView("_AddedCorrectlyView")); }
// GET: ShoppingCart public ActionResult ShoppingCartView() { ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); return(View(cart)); }
public ActionResult Login(LoginViewModel model, string returnUrl) { try { if (ModelState.IsValid) { if (Account.GetAccountByEmail(model.Email) != null) { Account record = Account.GetAccountByEmail(model.Email); var salt = record.Salt; var encodingPasswordString = Helper.EncodePassword(model.Password, salt); ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject(); List <Order> orderList = Order.ListByAccountID(record.ID); List <OrderItem> orderItemList = new List <OrderItem>(); if (encodingPasswordString == record.Password) { ViewBag.LoginFailed = false; Session["CurrentUser"] = record; Session["CurrentID"] = record.ID; UserModel.ID = record.ID; Session["CurrentUserName"] = record.FirstName; if (record.Role == 1) { Session["CurrentUserRole"] = record.Role; } foreach (Order o in orderList) { orderItemList = OrderItem.ListByOrderID(o.ID); foreach (OrderItem item in orderItemList) { cart.AddProductToCart(item.ProductID); } } if (record.Role == 1) { return(RedirectToAction(Constants.CONTROLLER_ADMIN, Constants.CONTROLLER_ADMIN)); } else { return(RedirectToAction(Constants.CONTROLLER_PRODUCT_LIST, Constants.CONTROLLER_PRODUCT_LIST)); } } else { ViewBag.LoginMessage = Constants.WRONG_USERNAME; ViewBag.LoginFailed = true; } } } else { ViewBag.LoginMessage = Constants.WRONG_USERNAME; ViewBag.LoginFailed = true; return(View()); } return(View(model)); } catch (Exception ignored) { ViewBag.LoginMessage = Constants.WRONG_USERNAME; ViewBag.LoginFailed = true; return(View()); } }