예제 #1
0
 public bool AddToCartAsync(int cartId, int ProductID)
 {
     myHandler = new BusinessLogicHandler();
     item = new CartItem();
     item = myHandler.CheckIfExist(cartId, ProductID);
     if(item == null)
     {
         item = new CartItem();
         item.CartID = cartId;
         item.ProductID = ProductID;
         item.DateAdded = DateTime.Now;
         item.Quantity = 1;
         if (myHandler.AddCartItem(item))
         { return true; }
         else
             return false;
     }
     else
     {
         item.Quantity += 1;
         if (myHandler.UpdateCartItem(item))
         { return true; }
         else
             return false;
     }
 }
예제 #2
0
        public async Task<ActionResult> UpdateQuantity(string quantity, string itemId)
        {

            string userName = User.Identity.GetUserName();
            ApplicationDbContext dataSocket = new ApplicationDbContext();
            UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(dataSocket);
            userMgr = new ApplicationUserManager(myStore);
            var user = await userMgr.FindByEmailAsync(userName);


            myHandler = new BusinessLogicHandler();
            CartItem item = new CartItem();
            item.CartItemID = Convert.ToInt32(itemId);
            item.CartID = user.Carts.CartID;
            item.Quantity = Convert.ToInt32(quantity);
            if (myHandler.UpdateCartItem(item))
            { return Redirect("/Cart/Edit"); }
            else
            { return Json("Error updating quantity"); }//
        }