private static ActivityLogCollection DBMapping(DBActivityLogCollection dbCollection) { if (dbCollection == null) return null; var collection = new ActivityLogCollection(); foreach (var dbItem in dbCollection) { var item = DBMapping(dbItem); collection.Add(item); } return collection; }
/// <summary> /// Gets all activity log items /// </summary> /// <param name="createdOnFrom">Log item creation from; null to load all customers</param> /// <param name="createdOnTo">Log item creation to; null to load all customers</param> /// <param name="email">Customer Email</param> /// <param name="username">Customer username</param> /// <param name="activityLogTypeId">Activity log type identifier</param> /// <param name="pageSize">Page size</param> /// <param name="pageIndex">Page index</param> /// <param name="totalRecords">Total records</param> /// <returns>Activity log collection</returns> public override DBActivityLogCollection GetAllActivities(DateTime?createdOnFrom, DateTime?createdOnTo, string email, string username, int activityLogTypeId, int pageSize, int pageIndex, out int totalRecords) { totalRecords = 0; var result = new DBActivityLogCollection(); Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_ActivityLogLoadAll"); if (createdOnFrom.HasValue) { db.AddInParameter(dbCommand, "CreatedOnFrom", DbType.DateTime, createdOnFrom.Value); } else { db.AddInParameter(dbCommand, "CreatedOnFrom", DbType.DateTime, null); } if (createdOnTo.HasValue) { db.AddInParameter(dbCommand, "CreatedOnTo", DbType.DateTime, createdOnTo.Value); } else { db.AddInParameter(dbCommand, "CreatedOnTo", DbType.DateTime, null); } db.AddInParameter(dbCommand, "Email", DbType.String, email); db.AddInParameter(dbCommand, "Username", DbType.String, username); if (activityLogTypeId > 0) { db.AddInParameter(dbCommand, "ActivityLogTypeID", DbType.Int32, activityLogTypeId); } else { db.AddInParameter(dbCommand, "ActivityLogTypeID", DbType.Int32, null); } db.AddInParameter(dbCommand, "PageSize", DbType.Int32, pageSize); db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, pageIndex); db.AddOutParameter(dbCommand, "TotalRecords", DbType.Int32, 0); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { var item = GetActivityLogFromReader(dataReader); result.Add(item); } } totalRecords = Convert.ToInt32(db.GetParameterValue(dbCommand, "@TotalRecords")); return(result); }