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"));
        }
Exemplo n.º 4
0
 // gets product recommendations for the shopping cart
 public static DataTable GetRecommendations()
 {
     return(ShoppingCartDAO.GetRecommendations());
 }
Exemplo n.º 5
0
 // Deletes old shopping carts
 public static bool DeleteOldCarts(byte days)
 {
     return(ShoppingCartDAO.DeleteOldCarts(days));
 }
Exemplo n.º 6
0
 // Create a new order from the shopping cart
 public static string CreateOrder(string customerName, string customerEmail, string customerAdderss)
 {
     return(ShoppingCartDAO.CreateOrder(customerEmail, customerEmail, customerAdderss));
 }
Exemplo n.º 7
0
 // Retrieve shopping cart items
 public static decimal GetTotalAmount()
 {
     return(ShoppingCartDAO.GetTotalAmount());
 }
Exemplo n.º 8
0
 // Counts old shopping carts
 public static int CountOldCarts(byte days)
 {
     return(ShoppingCartDAO.CountOldCarts(days));
 }
Exemplo n.º 9
0
 // Retrieve shopping cart items
 public static DataTable GetItems()
 {
     return(ShoppingCartDAO.GetItems());
 }
Exemplo n.º 10
0
 // Remove a shopping cart item
 public static bool RemoveItem(string productId)
 {
     return(ShoppingCartDAO.RemoveItem(productId));
 }
Exemplo n.º 11
0
 // Update the quantity of a shopping cart item
 public static bool UpdateItem(string productId, int quantity)
 {
     return(ShoppingCartDAO.UpdateItem(productId, quantity));
 }
Exemplo n.º 12
0
 // Add a new shopping cart item
 public static bool AddItem(string productId)
 {
     return(ShoppingCartDAO.AddItem(productId));
 }
Exemplo n.º 13
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public ShoppingCartBLL(LoggingSessionInfo pUserInfo)
 {
     this.CurrentUserInfo = pUserInfo;
     this._currentDAO     = new ShoppingCartDAO(pUserInfo);
 }