private static void ReadObject(UserBasket user, DbDataReader reader) { user.UserBasketId = int.Parse(reader["user_basket_id"].ToString()); user.UserId = int.Parse(reader["user_id"].ToString()); user.ProductId = int.Parse(reader["product_id"].ToString()); user.Quantity = int.Parse(reader["quantity"].ToString()); }
public static List <UserBasket> GetAllByUserId(int userId) { List <UserBasket> userBasketList = new List <UserBasket>(); UserBasket userBasket = new UserBasket(); using (DbConnection con = DBConnection.GetConnection()) { using (DbCommand command = con.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = " SELECT * FROM user_basket WHERE user_id = @user_id AND quantity > 0 "; command.Parameters.Add(DBConnection.GetNewParameter("@user_id", userId)); DbDataReader reader = command.ExecuteReader(); while (reader.Read()) { ReadObject(userBasket, reader); userBasketList.Add(userBasket); } } } return(userBasketList); }