Example #1
0
 public static int GetNumberQuantityInCart(string cookieID)
 {
     try
     {
         CartItemService cartItemService = new CartItemService();
         CartService     cartSerice      = new CartService();
         int             quantity        = 0;
         TblCart         cart            = cartSerice.GetByCookieID(cookieID);
         if (cart != null)
         {
             List <TblCartItem> cartItems = cartItemService.GetByCartID(cart.CartID);
             if (cartItems != null && cartItems.Count > 0)
             {
                 foreach (var item in cartItems)
                 {
                     quantity += item.NumberVariant;
                 }
             }
         }
         return(quantity);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         throw;
     }
 }
Example #2
0
 public bool UpdateTotalPrice(int cartID)
 {
     try
     {
         CartItemService cartItemService = new CartItemService();
         VariantService  variantService  = new VariantService();
         TblCart         cart            = GetByPrimaryKey(cartID);
         if (cart != null)
         {
             List <TblCartItem> cartItems  = cartItemService.GetByCartID(cartID);
             decimal            totalPrice = 0;
             if (cartItems != null && cartItems.Count > 0)
             {
                 foreach (var item in cartItems)
                 {
                     Variant variant = variantService.GetByPrimaryKey(item.VariantID);
                     if (variant != null)
                     {
                         totalPrice += (decimal)item.NumberVariant * (variant.VariantPrice != null ? variant.VariantPrice.Value : 0);
                     }
                 }
             }
             cart.TotalPrice = totalPrice;
             if (Update(cart))
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(false);
     }
 }