/// <summary> /// Gets an IP address from a data reader /// </summary> /// <param name="dataReader">IDataReader</param> /// <returns>DBBannedIpAddress</returns> private DBBannedIpAddress GetIpAddressFromReader(IDataReader dataReader) { var item = new DBBannedIpAddress(); item.BannedIpAddressId = NopSqlDataHelper.GetInt(dataReader, "BannedIpAddressID"); item.Address = NopSqlDataHelper.GetString(dataReader, "Address"); item.Comment = NopSqlDataHelper.GetString(dataReader, "Comment"); item.CreatedOn = NopSqlDataHelper.GetUtcDateTime(dataReader, "CreatedOn"); item.UpdatedOn = NopSqlDataHelper.GetUtcDateTime(dataReader, "UpdatedOn"); return(item); }
/// <summary> /// Gets all IP addresses /// </summary> /// <returns>IP address collection</returns> public override DBBannedIpAddressCollection GetIpAddressAll() { DBBannedIpAddressCollection ipCollection = new DBBannedIpAddressCollection(); Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_BannedIpAddressLoadAll"); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DBBannedIpAddress setting = GetIpAddressFromReader(dataReader); ipCollection.Add(setting); } } return(ipCollection); }
/// <summary> /// Gets an IP address by its ID /// </summary> /// <param name="bannedIpAddressID">IP address unique identifier</param> /// <returns>IP address</returns> public override DBBannedIpAddress GetIpAddressByID(int bannedIpAddressID) { DBBannedIpAddress ipAddress = null; Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_BannedIpAddressLoadByPrimaryKey"); db.AddInParameter(dbCommand, "BannedIpAddressID", DbType.Int32, bannedIpAddressID); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { ipAddress = GetIpAddressFromReader(dataReader); } } return(ipAddress); }
/// <summary> /// Updates an IP address /// </summary> /// <param name="bannedIpAddressID">IP address unique identifier</param> /// <param name="address">IP address</param> /// <param name="comment">Reason why the IP was banned</param> /// <param name="createdOn">When the record was last updated</param> /// <param name="updatedOn">When the record was last updated</param> /// <returns>Banned IP address</returns> public override DBBannedIpAddress UpdateBannedIpAddress(int bannedIpAddressID, string address, string comment, DateTime createdOn, DateTime updatedOn) { DBBannedIpAddress ipAddress = null; Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_BannedIpAddressUpdate"); db.AddInParameter(dbCommand, "BannedIpAddressID", DbType.Int32, bannedIpAddressID); db.AddInParameter(dbCommand, "Address", DbType.String, address); db.AddInParameter(dbCommand, "Comment", DbType.String, comment); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, createdOn); db.AddInParameter(dbCommand, "UpdatedOn", DbType.DateTime, updatedOn); if (db.ExecuteNonQuery(dbCommand) > 0) { ipAddress = GetIpAddressByID(bannedIpAddressID); } return(ipAddress); }
/// <summary> /// Inserts an IP address /// </summary> /// <param name="address">IP address</param> /// <param name="comment">Reason why the IP was banned</param> /// <param name="createdOn">When the record was inserted</param> /// <param name="updatedOn">When the record was last updated</param> /// <returns>IP address</returns> public override DBBannedIpAddress InsertBannedIpAddress(string address, string comment, DateTime createdOn, DateTime updatedOn) { DBBannedIpAddress item = null; Database db = NopSqlDataHelper.CreateConnection(_sqlConnectionString); DbCommand dbCommand = db.GetStoredProcCommand("Nop_BannedIpAddressInsert"); db.AddOutParameter(dbCommand, "BannedIpAddressID", DbType.Int32, 0); db.AddInParameter(dbCommand, "Address", DbType.String, address); db.AddInParameter(dbCommand, "Comment", DbType.String, comment); db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, createdOn); db.AddInParameter(dbCommand, "UpdatedOn", DbType.DateTime, updatedOn); if (db.ExecuteNonQuery(dbCommand) > 0) { int ipAddressId = Convert.ToInt32(db.GetParameterValue(dbCommand, "@BannedIpAddressID")); item = GetIpAddressById(ipAddressId); } return(item); }