public IActionResult LogIn([FromBody] DTO.Principal principal) { PrincipalDAO dao = new PrincipalDAO(_context); string role = dao.CheckLogin(principal.Username, principal.Password); if (role == "admin" || role == "user") { HttpContext.Session.SetString("USER", principal.Username); HttpContext.Session.SetString("ROLE", role); if (role == "user") { ShoppingCartDAO scDAO = new ShoppingCartDAO(_context); List <DTO.Accessory> listAccCart = scDAO.FindAllAccCartByUsername(principal.Username); Dictionary <string, DTO.Accessory> cart = new Dictionary <string, DTO.Accessory>(); foreach (var item in listAccCart) { DTO.ShoppingCart.AddCart(item, cart); } HttpContext.Session.SetCollectionAsJson("cart", cart); var a = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart"); } TempData["msg"] = "Login successfully"; } else { TempData["msg"] = "Login failed"; } return(new JsonResult(role)); }
public IActionResult LogInSyn([FromBody] DTO.Principal principal) { PrincipalDAO dao = new PrincipalDAO(_context); string role = dao.CheckLogin(principal.Username, principal.Password); if (role == "admin" || role == "user") { HttpContext.Session.SetString("USER", principal.Username); HttpContext.Session.SetString("ROLE", role); if (role == "user") { ShoppingCartDAO scDAO = new ShoppingCartDAO(_context); List <DTO.Accessory> listAccCart = scDAO.FindAllAccCartByUsername(principal.Username); Dictionary <string, DTO.Accessory> cart = new Dictionary <string, DTO.Accessory>(); foreach (var item in listAccCart) { DTO.ShoppingCart.AddCart(item, cart); } HttpContext.Session.SetCollectionAsJson("cart", cart); } TempData["msg"] = "Register successful"; TempData["msg-details"] = "System automatically log in your account."; } else { TempData["msg"] = "Register failed"; } return(RedirectToAction("Index", "Home"));; }
public IActionResult LogOut() { string username = HttpContext.Session.GetString("USER"); if (username != null) { Dictionary <string, DTO.Accessory> dict = HttpContext.Session.GetCollectionFromJson <Dictionary <string, DTO.Accessory> >("cart"); if (dict != null) { ShoppingCartDAO dao = new ShoppingCartDAO(_context); if (dao.CheckEmptyByUsername(username)) { if (!dao.DeleteAllByUsername(username)) { ViewData["msg"] = "Delete all accessories in cart failed."; return(View("Error Page")); } } if (dict.Count > 0) { if (!dao.InsertAll(dict, username)) { ViewData["msg"] = "Insert all accessories to cart failed."; return(View("Error Page")); } } } HttpContext.Session.Clear(); } return(RedirectToAction("Index", "Home")); }
// gets product recommendations for the shopping cart public static DataTable GetRecommendations() { return(ShoppingCartDAO.GetRecommendations()); }
// Deletes old shopping carts public static bool DeleteOldCarts(byte days) { return(ShoppingCartDAO.DeleteOldCarts(days)); }
// Create a new order from the shopping cart public static string CreateOrder(string customerName, string customerEmail, string customerAdderss) { return(ShoppingCartDAO.CreateOrder(customerEmail, customerEmail, customerAdderss)); }
// Retrieve shopping cart items public static decimal GetTotalAmount() { return(ShoppingCartDAO.GetTotalAmount()); }
// Counts old shopping carts public static int CountOldCarts(byte days) { return(ShoppingCartDAO.CountOldCarts(days)); }
// Retrieve shopping cart items public static DataTable GetItems() { return(ShoppingCartDAO.GetItems()); }
// Remove a shopping cart item public static bool RemoveItem(string productId) { return(ShoppingCartDAO.RemoveItem(productId)); }
// Update the quantity of a shopping cart item public static bool UpdateItem(string productId, int quantity) { return(ShoppingCartDAO.UpdateItem(productId, quantity)); }
// Add a new shopping cart item public static bool AddItem(string productId) { return(ShoppingCartDAO.AddItem(productId)); }
/// <summary> /// 构造函数 /// </summary> public ShoppingCartBLL(LoggingSessionInfo pUserInfo) { this.CurrentUserInfo = pUserInfo; this._currentDAO = new ShoppingCartDAO(pUserInfo); }