Ejemplo n.º 1
0
 /// <summary>
 /// Add an item to the cart.
 /// When ItemId to be added has already existed, this method will update the quantity instead.
 /// </summary>
 /// <param name="item">Item to add</param>
 public void Add(CartItemInfo item)
 {
     CartItemInfo cartItem;
     if (!cartItems.TryGetValue(item.ItemId, out cartItem))
         cartItems.Add(item.ItemId, item);
     else
         cartItem.Quantity += item.Quantity;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Add an item to the cart.
 /// When ItemId to be added has already existed, this method will update the quantity instead.
 /// </summary>
 /// <param name="itemId">Item Id of item to add</param>
 public void Add(string itemId)
 {
     CartItemInfo cartItem;
     if (!cartItems.TryGetValue(itemId, out cartItem)) {
         Item item = new Item();
         ItemInfo data = item.GetItem(itemId);
         if (data != null) {
             CartItemInfo newItem = new CartItemInfo(itemId, data.ProductName, 1, (decimal)data.Price, data.Name, data.CategoryId, data.ProductId);
             cartItems.Add(itemId, newItem);
         }
     }
     else
         cartItem.Quantity++;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve collection of shopping cart items
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <param name="appName">Application Name</param>
        /// <param name="isShoppingCart">Shopping cart flag</param>
        /// <returns>Collection of shopping cart items</returns>
        public IList<CartItemInfo> GetCartItems(string userName, string appName, bool isShoppingCart)
        {
            string sqlSelect = "SELECT Cart.ItemId, Cart.Name, Cart.Type, Cart.Price, Cart.CategoryId, Cart.ProductId, Cart.Quantity FROM Profiles, Cart WHERE Profiles.UniqueID = Cart.UniqueID AND Profiles.Username = :Username AND Profiles.ApplicationName = :ApplicationName AND IsShoppingCart = :IsShoppingCart";

            OracleParameter[] parms = {
                new OracleParameter(":Username", OracleType.VarChar, 256),
                new OracleParameter(":ApplicationName", OracleType.VarChar, 256),
                new OracleParameter(":IsShoppingCart", OracleType.VarChar, 1)};
            parms[0].Value = userName;
            parms[1].Value = appName;
            parms[2].Value = OracleHelper.OraBit(isShoppingCart);

            OracleDataReader dr = OracleHelper.ExecuteReader(OracleHelper.ConnectionStringProfile, CommandType.Text, sqlSelect, parms);

            IList<CartItemInfo> cartItems = new List<CartItemInfo>();

            while(dr.Read()) {
                CartItemInfo cartItem = new CartItemInfo(dr.GetString(0), dr.GetString(1), dr.GetInt32(6), dr.GetDecimal(3), dr.GetString(2), dr.GetString(4), dr.GetString(5));
                cartItems.Add(cartItem);
            }
            dr.Close();
            return cartItems;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieve collection of shopping cart items
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <param name="appName">Application Name</param>
        /// <param name="isShoppingCart">Shopping cart flag</param>
        /// <returns>Collection of shopping cart items</returns>
        public IList<CartItemInfo> GetCartItems(string userName, string appName, bool isShoppingCart)
        {
            string sqlSelect = "SELECT Cart.ItemId, Cart.Name, Cart.Type, Cart.Price, Cart.CategoryId, Cart.ProductId, Cart.Quantity FROM Profiles INNER JOIN Cart ON Profiles.UniqueID = Cart.UniqueID WHERE Profiles.Username = @Username AND Profiles.ApplicationName = @ApplicationName AND IsShoppingCart = @IsShoppingCart;";

            SqlParameter[] parms = {
                new SqlParameter("@Username", SqlDbType.VarChar, 256),
                new SqlParameter("@ApplicationName", SqlDbType.VarChar, 256),
                new SqlParameter("@IsShoppingCart", SqlDbType.Bit)};
            parms[0].Value = userName;
            parms[1].Value = appName;
            parms[2].Value = isShoppingCart;

            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringProfile, CommandType.Text, sqlSelect, parms);

            IList<CartItemInfo> cartItems = new List<CartItemInfo>();

            while(dr.Read()) {
                CartItemInfo cartItem = new CartItemInfo(dr.GetString(0), dr.GetString(1), dr.GetInt32(6), dr.GetDecimal(3), dr.GetString(2), dr.GetString(4), dr.GetString(5));
                cartItems.Add(cartItem);
            }
            dr.Close();
            return cartItems;
        }