Exemplo n.º 1
0
 public void RemoveCartItem(int Id)
 {
     try
     {
         using (SqlConnection _con = CommonSqlDAO.GetConnection())
         {
             using (SqlCommand cmd = new SqlCommand("Usp_Cart_D", _con))
             {
                 cmd.Parameters.AddWithValue("@Id", Id);
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.ExecuteNonQuery();
             }
         }
     }
     finally
     {
         CommonSqlDAO.CloseConnection();
     }
 }
Exemplo n.º 2
0
 public void SaveToCart(Cart cart)
 {
     try
     {
         using (SqlConnection _con = CommonSqlDAO.GetConnection())
         {
             using (SqlCommand cmd = new SqlCommand("Usp_Cart_IU", _con))
             {
                 cmd.Parameters.AddWithValue("@Id", cart.Id);
                 cmd.Parameters.AddWithValue("@ProductId", cart.ProductId);
                 cmd.Parameters.AddWithValue("@Quantity", cart.Quantity);
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.ExecuteNonQuery();
             }
         }
     }
     finally
     {
         CommonSqlDAO.CloseConnection();
     }
 }
Exemplo n.º 3
0
        public IEnumerable <Product> GetProduct()
        {
            List <Product> productList = new List <Product>();

            try
            {
                using (SqlConnection _con = CommonSqlDAO.GetConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("Usp_GetProduct", _con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                Product product = new Product();
                                product.Id             = rdr["Id"] == DBNull.Value ? 0 : Convert.ToInt32(rdr["Id"]);
                                product.ProductName    = rdr["ProductName"] == DBNull.Value ? string.Empty : Convert.ToString(rdr["ProductName"]);
                                product.ProductDetails = rdr["ProductDetails"] == DBNull.Value ? string.Empty : Convert.ToString(rdr["ProductDetails"]);
                                product.Price          = rdr["Price"] == DBNull.Value ? 0 : Convert.ToDecimal(rdr["Price"]);
                                product.Quantity       = rdr["Quantity"] == DBNull.Value ? 0 : Convert.ToInt32(rdr["Quantity"]);
                                product.ProductImg     = rdr["ProductImg"] == DBNull.Value ? string.Empty : Convert.ToString(rdr["ProductImg"]);
                                product.IsInCart       = rdr["IsInCart"] == DBNull.Value ? false : Convert.ToBoolean(rdr["IsInCart"]);

                                productList.Add(product);
                            }
                        }
                    }
                }
                return(productList);
            }
            finally
            {
                CommonSqlDAO.CloseConnection();
            }
        }
Exemplo n.º 4
0
        public IEnumerable <CartDetail> GetCartProduct()
        {
            List <CartDetail> cartList = new List <CartDetail>();

            try
            {
                using (SqlConnection _con = CommonSqlDAO.GetConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("Usp_GetCartProduct", _con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        using (SqlDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                CartDetail cartDetail = new CartDetail();
                                cartDetail.Id             = rdr["cartId"] == DBNull.Value ? 0 : Convert.ToInt32(rdr["cartId"]);
                                cartDetail.ProductId      = rdr["ProductId"] == DBNull.Value ? 0 : Convert.ToInt32(rdr["ProductId"]);
                                cartDetail.Quantity       = rdr["Quantity"] == DBNull.Value ? 0 : Convert.ToInt32(rdr["Quantity"]);
                                cartDetail.ProductName    = rdr["ProductName"] == DBNull.Value ? string.Empty : Convert.ToString(rdr["ProductName"]);
                                cartDetail.ProductDetails = rdr["ProductDetails"] == DBNull.Value ? string.Empty : Convert.ToString(rdr["ProductDetails"]);
                                cartDetail.Price          = rdr["Price"] == DBNull.Value ? 0 : Convert.ToDecimal(rdr["Price"]);
                                cartDetail.ProductImg     = rdr["ProductImg"] == DBNull.Value ? string.Empty : Convert.ToString(rdr["ProductImg"]);
                                cartDetail.StockQuantity  = rdr["cartId"] == DBNull.Value ? 0 : Convert.ToInt32(rdr["StockQuantity"]);
                                cartList.Add(cartDetail);
                            }
                        }
                    }
                }
                return(cartList);
            }
            finally
            {
                CommonSqlDAO.CloseConnection();
            }
        }