コード例 #1
0
        public async Task <IActionResult> AddToCart(int cartid)
        {
            var         userID   = (await userManager.FindByNameAsync(User.Identity.Name)).Id;
            TblWishList WishCart = dbGamingShop.TblWishLists
                                   .FirstOrDefault(x => x.ispaied == false && x.CustomerId == userID);

            if (WishCart != null)
            {
                if (dbGamingShop.TblWishListItems.Count(x =>
                                                        x.WishCartId == WishCart.Id && x.ProductId == cartid) > 0)
                {
                    return(Json(true));
                }
            }
            if (WishCart == null)
            {
                WishCart = new TblWishList
                {
                    creationDate = DateTime.Now,
                    CustomerId   = userID,
                    ispaied      = false,
                };
                dbGamingShop.Add(WishCart);
                dbGamingShop.SaveChanges();
            }
            if (dbGamingShop.TblWishListItems.Count(x => x.WishCartId == WishCart.Id && x.ProductId == cartid)
                == 0)
            {
                TblWishListItem WishListCartItem = new TblWishListItem()
                {
                    count      = 1,
                    ProductId  = cartid,
                    WishCartId = WishCart.Id
                };
                dbGamingShop.Add(WishListCartItem);
                dbGamingShop.SaveChanges();
                return(Json(true));
            }
            else
            {
                return(Json(false));
            }
        }
コード例 #2
0
 public IActionResult RemoveFromWishList(int WishListItemId)
 {
     try
     {
         TblWishListItem WishListCartItem = dbGamingShop.Find <TblWishListItem>(WishListItemId);
         int             WishListcartid   = WishListCartItem.WishCartId;
         dbGamingShop.Remove <TblWishListItem>(WishListCartItem);
         dbGamingShop.SaveChanges();
         return(Json(new
         {
             status = true,
             totalsum = $"{CalculateTotalSumWishList(WishListcartid):0,0} تومان",
             count = dbGamingShop.TblPurchaseCartItems.Count(x => x.PurchaseCartId == WishListcartid)
         }));
     }
     catch
     {
         return(Json(false));
     }
 }