private static DiscountUsageHistoryCollection DBMapping(DBDiscountUsageHistoryCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            var collection = new DiscountUsageHistoryCollection();

            foreach (var dbItem in dbCollection)
            {
                var item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
Example #2
0
        /// <summary>
        /// Gets all discount usage history entries
        /// </summary>
        /// <param name="discountId">Discount type identifier; null to load all</param>
        /// <param name="customerId">Customer identifier; null to load all</param>
        /// <param name="orderId">Order identifier; null to load all</param>
        /// <returns>Discount usage history entries</returns>
        public override DBDiscountUsageHistoryCollection GetAllDiscountUsageHistoryEntries(int?discountId,
                                                                                           int?customerId, int?orderId)
        {
            var       result    = new DBDiscountUsageHistoryCollection();
            Database  db        = NopSqlDataHelper.CreateConnection(_sqlConnectionString);
            DbCommand dbCommand = db.GetStoredProcCommand("Nop_DiscountUsageHistoryLoadAll");

            if (discountId.HasValue)
            {
                db.AddInParameter(dbCommand, "DiscountID", DbType.Int32, discountId.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "DiscountID", DbType.Int32, null);
            }
            if (customerId.HasValue)
            {
                db.AddInParameter(dbCommand, "CustomerID", DbType.Int32, customerId.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "CustomerID", DbType.Int32, null);
            }
            if (orderId.HasValue)
            {
                db.AddInParameter(dbCommand, "OrderID", DbType.Int32, orderId.Value);
            }
            else
            {
                db.AddInParameter(dbCommand, "OrderID", DbType.Int32, null);
            }
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    var item = GetDiscountUsageHistoryFromReader(dataReader);
                    result.Add(item);
                }
            }

            return(result);
        }