/// <summary>
        /// Gets an IP network from a data reader
        /// </summary>
        /// <param name="dataReader">IDataReader</param>
        /// <returns>DBBannedIpNetwork</returns>
        private DBBannedIpNetwork GetIpNetworkFromReader(IDataReader dataReader)
        {
            DBBannedIpNetwork ipNetwork = new DBBannedIpNetwork();

            ipNetwork.BannedIpNetworkID = NopSqlDataHelper.GetInt(dataReader, "BannedIpNetworkID");
            ipNetwork.StartAddress      = NopSqlDataHelper.GetString(dataReader, "StartAddress");
            ipNetwork.EndAddress        = NopSqlDataHelper.GetString(dataReader, "EndAddress");
            ipNetwork.Comment           = NopSqlDataHelper.GetString(dataReader, "Comment");
            ipNetwork.IpException       = NopSqlDataHelper.GetString(dataReader, "IpException");
            ipNetwork.CreatedOn         = NopSqlDataHelper.GetUtcDateTime(dataReader, "CreatedOn");
            ipNetwork.UpdatedOn         = NopSqlDataHelper.GetUtcDateTime(dataReader, "UpdatedOn");
            return(ipNetwork);
        }
        /// <summary>
        /// Gets an IP Network by its ID
        /// </summary>
        /// <param name="bannedIpNetworkID">IP network unique identifier</param>
        /// <returns>IP network</returns>
        public override DBBannedIpNetwork GetIpNetworkByID(int bannedIpNetworkID)
        {
            DBBannedIpNetwork ipNetwork = null;
            Database          db        = NopSqlDataHelper.CreateConnection(_sqlConnectionString);
            DbCommand         dbCommand = db.GetStoredProcCommand("Nop_BannedIpNetworkLoadByPrimaryKey");

            db.AddInParameter(dbCommand, "BannedIpNetworkID", DbType.Int32, bannedIpNetworkID);
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    ipNetwork = GetIpNetworkFromReader(dataReader);
                }
            }
            return(ipNetwork);
        }
        /// <summary>
        /// Gets all IP networks
        /// </summary>
        /// <returns>IP network collection</returns>
        public override DBBannedIpNetworkCollection GetIpNetworkAll()
        {
            DBBannedIpNetworkCollection ipCollection = new DBBannedIpNetworkCollection();
            Database  db        = NopSqlDataHelper.CreateConnection(_sqlConnectionString);
            DbCommand dbCommand = db.GetStoredProcCommand("Nop_BannedIpNetworkLoadAll");

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    DBBannedIpNetwork ipNetwork = GetIpNetworkFromReader(dataReader);
                    ipCollection.Add(ipNetwork);
                }
            }
            return(ipCollection);
        }
        /// <summary>
        /// Updates an IP network
        /// </summary>
        /// <param name="bannedIpNetworkID">IP network unique identifier</param>
        /// <param name="startAddress">First IP address in the range</param>
        /// <param name="endAddress">Last IP address in the range</param>
        /// <param name="comment">Reason why the IP network was banned</param>
        /// <param name="ipException">Exceptions within the range</param>
        /// <param name="createdOn">When the record was inserted</param>
        /// <param name="updatedOn">When the record was last updated</param>
        /// <returns>IP network</returns>
        public override DBBannedIpNetwork UpdateBannedIpNetwork(int bannedIpNetworkID, string startAddress, string endAddress, string comment, string ipException, DateTime createdOn, DateTime updatedOn)
        {
            DBBannedIpNetwork ipNetwork = null;
            Database          db        = NopSqlDataHelper.CreateConnection(_sqlConnectionString);
            DbCommand         dbCommand = db.GetStoredProcCommand("Nop_BannedIpNetworkUpdate");

            db.AddInParameter(dbCommand, "BannedIpNetworkID", DbType.Int32, bannedIpNetworkID);
            db.AddInParameter(dbCommand, "StartAddress", DbType.String, startAddress);
            db.AddInParameter(dbCommand, "EndAddress", DbType.String, endAddress);
            db.AddInParameter(dbCommand, "Comment", DbType.String, comment);
            db.AddInParameter(dbCommand, "IpException", DbType.String, ipException);
            db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, createdOn);
            db.AddInParameter(dbCommand, "UpdatedOn", DbType.DateTime, updatedOn);
            if (db.ExecuteNonQuery(dbCommand) > 0)
            {
                ipNetwork = GetIpNetworkByID(bannedIpNetworkID);
            }

            return(ipNetwork);
        }
        /// <summary>
        /// Inserts an IP network
        /// </summary>
        /// <param name="startAddress">First IP address in the range</param>
        /// <param name="endAddress">Last IP address in the range</param>
        /// <param name="comment">Reason why the IP network was banned</param>
        /// <param name="ipException">Exceptions in the range</param>
        /// <param name="createdOn">When the record was inserted</param>
        /// <param name="updatedOn">When the record was last updated</param>
        /// <returns>IP network</returns>
        public override DBBannedIpNetwork InsertBannedIpNetwork(string startAddress,
                                                                string endAddress, string comment, string ipException,
                                                                DateTime createdOn, DateTime updatedOn)
        {
            DBBannedIpNetwork item      = null;
            Database          db        = NopSqlDataHelper.CreateConnection(_sqlConnectionString);
            DbCommand         dbCommand = db.GetStoredProcCommand("Nop_BannedIpNetworkInsert");

            db.AddOutParameter(dbCommand, "BannedIpNetworkID", DbType.Int32, 0);
            db.AddInParameter(dbCommand, "StartAddress", DbType.String, startAddress);
            db.AddInParameter(dbCommand, "EndAddress", DbType.String, endAddress);
            db.AddInParameter(dbCommand, "Comment", DbType.String, comment);
            db.AddInParameter(dbCommand, "IpException", DbType.String, ipException);
            db.AddInParameter(dbCommand, "CreatedOn", DbType.DateTime, createdOn);
            db.AddInParameter(dbCommand, "UpdatedOn", DbType.DateTime, updatedOn);
            if (db.ExecuteNonQuery(dbCommand) > 0)
            {
                int ipNetworkId = Convert.ToInt32(db.GetParameterValue(dbCommand, "@BannedIpNetworkID"));
                item = GetIpNetworkById(ipNetworkId);
            }
            return(item);
        }