コード例 #1
0
ファイル: CartItemData.cs プロジェクト: pnthu/ShoesStore
        //load tất cả sản phẩm trong giỏ hàng
        public List <CartItemDTO> GetCartItemsByCartID(int cartID)
        {
            List <CartItemDTO> listCartItems = new List <CartItemDTO>();
            string             sql           = "Select * From CartItem Where cartID = @cartID";
            SqlConnection      cnn           = new SqlConnection(Consts.Consts.connectionString);

            if (cnn.State == ConnectionState.Closed)
            {
                cnn.Open();
            }
            SqlCommand cmd = new SqlCommand(sql, cnn);

            cmd.Parameters.AddWithValue("@cartID", cartID);
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                int         productDetailID = (int)dr[1];
                int         quantity        = (int)dr[2];
                ProductDTO  product         = new ProductData().GetProductByProductDetailID(productDetailID);
                double      price           = product.Price;
                string      color           = product.Color;
                string      name            = new ShoesData().GetShoesDetailByProductID(product.ProductId).Name;
                double      size            = new ProductDetailData().GetSizeByProductDetailID(productDetailID);
                CartItemDTO dto             = new CartItemDTO {
                    ProductDetailId = productDetailID, Quantity = quantity, Price = (float)price, Color = color, Name = name, Size = size
                };
                dto.Image = new ProductImageData().GetImageByProductID(new ProductData().GetProductByProductDetailID(dto.ProductDetailId).ProductId);
                listCartItems.Add(dto);
            }
            cnn.Close();
            return(listCartItems);
        }
コード例 #2
0
ファイル: CartItemData.cs プロジェクト: pnthu/ShoesStore
        private bool UpdateQuantityInvalidCartItems(List <CartItemDTO> listCartItems)
        {
            bool       result         = true;
            List <int> listQuantities = new ProductDetailData().GetAvailableQuantityByProductDetailIDs(listCartItems);

            for (int i = 0; i < listCartItems.Count; i++)
            {
                if (listCartItems[i].Quantity > listQuantities[i])
                {
                    listCartItems[i].Quantity = listQuantities[i];
                    result = false;
                }
            }
            UpdateCartItemsQuantity(listCartItems);
            return(result);
        }