context: /* Yet Another Forum.NET
   * Copyright (C) 2006-2013 Jaben Cargman
   * http://www.yetanotherforum.net/
   * 
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License
   * as published by the Free Software Foundation; either version 2
   * of the License, or (at your option) any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   */
  
  namespace YAF.Controls
  {
      #region Using
  
      using System;
      using System.Collections.Generic;
      using System.Data;
      using System.Linq;
      using System.Web.Security;
  
      using YAF.Classes;
      using YAF.Classes.Data;
      using YAF.Core;
      using YAF.Core.Extensions;
      using YAF.Core.Model;
      using YAF.Core.Services.CheckForSpam;
      using YAF.Types;
      using YAF.Types.Constants;
      using YAF.Types.Extensions;
      using YAF.Types.Interfaces;
      using YAF.Types.Models;
      using YAF.Utils;
      using YAF.Utils.Helpers;
  
      #endregion
  
      /// <summary>
      /// The edit users kill.
      /// </summary>
      public partial class EditUsersKill : BaseUserControl
      {
          #region Constants and Fields
  
          /// <summary>
          ///   The _all posts by user.
          /// </summary>
          private DataTable _allPostsByUser;
  
          #endregion
  
          #region Properties
  
          /// <summary>
          ///   Gets AllPostsByUser.
          /// </summary>
          public DataTable AllPostsByUser
          {
              get
              {
                  return this._allPostsByUser
                         ?? (this._allPostsByUser =
                             LegacyDb.post_alluser(
                                 this.PageContext.PageBoardID,
                                 this.CurrentUserID,
                                 this.PageContext.PageUserID,
                                 null));
              }
          }
  
          /// <summary>
          ///   Gets IPAddresses.
          /// </summary>
          [NotNull]
          public List<string> IPAddresses
          {
              get
              {
                  var ipList = this.AllPostsByUser.GetColumnAsList<string>("IP").OrderBy(x => x).Distinct().ToList();
  
                  if (ipList.Count.Equals(0))
                  {
                      ipList.Add(this.CurrentUserDataHelper.LastIP);
                  }
  
                  return ipList;
              }
          }
  
          /// <summary>
          /// Gets the current user data helper.
          /// </summary>
          /// <value>
          /// The current user data helper.
          /// </value>
          public CombinedUserDataHelper CurrentUserDataHelper
          {
              get
              {
                  var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID);
                  var currentUserId = this.CurrentUserID;
  
                  return currentUserId != null
                             ? new CombinedUserDataHelper(user, currentUserId.Value.ToType<int>())
                             : null;
              }
          }
  
          /// <summary>
          ///   Gets CurrentUserID.
          /// </summary>
          protected long? CurrentUserID
          {
              get
              {
                  return this.PageContext.QueryIDs["u"];
              }
          }
  
          #endregion
  
          #region Methods
  
          /// <summary>
          /// Kills the User
          /// </summary>
          /// <param name="sender">The source of the event.</param>
          /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
          protected void Kill_OnClick([NotNull] object sender, [NotNull] EventArgs e)
          {
              if (this.BanIps.Checked)
              {
                  this.BanUserIps();
              }
  
              this.DeletePosts();
  
              MembershipUser user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID);
              this.PageContext.AddLoadMessage(
                  this.Get<ILocalization>().GetText("ADMIN_EDITUSER", "MSG_USER_KILLED").FormatWith(user.UserName));
  
              // update the displayed data...
              this.BindData();
          }
  
          /// <summary>
          /// Reports the User
          /// </summary>
          /// <param name="sender">The source of the event.</param>
          /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
          protected void Report_OnClick([NotNull] object sender, [NotNull] EventArgs e)
          {
              if (this.Get<YafBoardSettings>().StopForumSpamApiKey.IsNotSet())
              {
                  return;
              }
  
              var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID);
  
              try
              {
                  var stopForumSpam = new StopForumSpam();
  
                  if (!stopForumSpam.ReportUserAsBot(this.IPAddresses.FirstOrDefault(), user.Email, user.UserName))
                  {
                      return;
                  }
  
                  this.PageContext.AddLoadMessage(this.GetText("ADMIN_EDITUSER", "BOT_REPORTED"), MessageTypes.Success);
  
                  this.Logger.Log(
                      this.PageContext.PageUserID,
                      "User Reported to StopForumSpam.com".FormatWith(user.UserName, this.CurrentUserID),
                      "User (Name:{0}/ID:{1}/IP:{2}/Email:{3}) Reported to StopForumSpam.com by {4}".FormatWith(
                          user.UserName,
                          this.CurrentUserID,
                          this.IPAddresses.FirstOrDefault(),
                          user.Email,
                          this.Get<YafBoardSettings>().EnableDisplayName
                              ? this.PageContext.CurrentUserData.DisplayName
                              : this.PageContext.CurrentUserData.UserName),
                      EventLogTypes.Information);
              }
              catch (Exception exception)
              {
                  this.PageContext.AddLoadMessage(
                      this.GetText("ADMIN_EDITUSER", "BOT_REPORTED_FAILED"),
                      MessageTypes.Error);
  
                  this.Logger.Log(
                      this.PageContext.PageUserID,
                      "User (Name{0}/ID:{1}) Report to StopForumSpam.com Failed".FormatWith(
                          user.UserName,
                          this.CurrentUserID),
                      exception);
              }
          }
  
          /// <summary>
          /// Handles the Load event of the Page control.
          /// </summary>
          /// <param name="sender">The source of the event.</param>
          /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
          protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
          {
              // init ids...
  
gt:             this.PageContext.QueryIDs = new QueryStringIDHelper("u", true);