public HttpResponseMessage GetSoftDeletedUsers(Newtonsoft.Json.Linq.JObject requestJson)
        {
            UserResult result = new UserResult();
            try
            {
                //return a summary of the number of deleted users
                if (this.PortalSettings == null) throw new ArgumentNullException("PortalSettings object");
                int portalId = this.PortalSettings.PortalId;
                UserController uc = new UserController();
                List<string> usernames = new List<string>();
                result.UsersAffected = 0;
                IDataReader reader = Data.SqlDataProvider.Instance().GetDeletedUsers(portalId);
                if (reader.Read())
                {
                    //total number of soft-deleted users
                    result.UsersRemaining = (int)reader[0];
                }
                if (reader.NextResult())
                {
                    //first ten usernames of soft-deleted users
                    while (reader.Read())
                    {
                        string username = (string)reader["UserName"];
                        int userId = (int)reader["UserId"];
                        UserInfo user = UserController.GetUser(portalId, userId, true);
                        result.UsersAffected++;
                        if (user != null)
                        {
                            string folderPath = ((PathUtils)PathUtils.Instance).GetUserFolderPath(user);
                            usernames.Add(username + " [" + userId.ToString() + "] - " + folderPath);
                        }
                        else
                            usernames.Add(username + " [" + userId.ToString() + "] - [no folder]");
                    }
                }
                
                result.Success = true;
                if (result.UsersRemaining > 0)
                {
                    //last ten soft-deleted usernames
                    if (result.UsersRemaining >= 10)
                    {
                        result.Message = "First ten soft-deleted users found:";
                    }
                    else
                    {
                        result.Message = "Found " + result.UsersAffected.ToString() + " Deleted Users:";
                    }
                    foreach (string user in usernames)
                        result.Message += user + ", ";
                }
                else
                    result.Message = "No Deleted Users Found";

                if (result.UsersRemaining > 10 && reader.NextResult())
                {
                    //count the last 10 users, but don't re-show existing users shown in first ten
                    int numberToCount = result.UsersRemaining - 10;
                    usernames = new List<string>();
                    for (int i = result.UsersAffected - 10; i <= result.UsersAffected; i++)
                    {
                        if (reader.Read())
                        {
                            usernames.Add((string)reader["UserName"]);
                            result.UsersAffected++;
                        }
                        else
                            break;
                    }

                    if (usernames.Count > 0)
                    {
                        result.Message += "\nLast Deleted Users: (";
                        foreach (string user in usernames)
                            result.Message += user + ", ";
                        result.Message += ")";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Error = ex.Message;
                result.StackTrace = ex.StackTrace;
            }
            finally
            {
                result.UserName = User.Identity.Name;
                result.WasAuthorised = User.Identity.IsAuthenticated;
            }
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }
        public HttpResponseMessage GetSoftDeletedUsers(Newtonsoft.Json.Linq.JObject requestJson)
        {
            UserResult result = new UserResult();

            try
            {
                //return a summary of the number of deleted users
                if (this.PortalSettings == null)
                {
                    throw new ArgumentNullException("PortalSettings object");
                }
                int            portalId  = this.PortalSettings.PortalId;
                UserController uc        = new UserController();
                List <string>  usernames = new List <string>();
                result.UsersAffected = 0;
                IDataReader reader = Data.SqlDataProvider.Instance().GetDeletedUsers(portalId);
                if (reader.Read())
                {
                    //total number of soft-deleted users
                    result.UsersRemaining = (int)reader[0];
                }
                if (reader.NextResult())
                {
                    //first ten usernames of soft-deleted users
                    while (reader.Read())
                    {
                        string   username = (string)reader["UserName"];
                        int      userId   = (int)reader["UserId"];
                        UserInfo user     = UserController.GetUser(portalId, userId, true);
                        result.UsersAffected++;
                        if (user != null)
                        {
                            string folderPath = ((PathUtils)PathUtils.Instance).GetUserFolderPath(user);
                            usernames.Add(username + " [" + userId.ToString() + "] - " + folderPath);
                        }
                        else
                        {
                            usernames.Add(username + " [" + userId.ToString() + "] - [no folder]");
                        }
                    }
                }

                result.Success = true;
                if (result.UsersRemaining > 0)
                {
                    //last ten soft-deleted usernames
                    if (result.UsersRemaining >= 10)
                    {
                        result.Message = "First ten soft-deleted users found:";
                    }
                    else
                    {
                        result.Message = "Found " + result.UsersAffected.ToString() + " Deleted Users:";
                    }
                    foreach (string user in usernames)
                    {
                        result.Message += user + ", ";
                    }
                }
                else
                {
                    result.Message = "No Deleted Users Found";
                }

                if (result.UsersRemaining > 10 && reader.NextResult())
                {
                    //count the last 10 users, but don't re-show existing users shown in first ten
                    int numberToCount = result.UsersRemaining - 10;
                    usernames = new List <string>();
                    for (int i = result.UsersAffected - 10; i <= result.UsersAffected; i++)
                    {
                        if (reader.Read())
                        {
                            usernames.Add((string)reader["UserName"]);
                            result.UsersAffected++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (usernames.Count > 0)
                    {
                        result.Message += "\nLast Deleted Users: (";
                        foreach (string user in usernames)
                        {
                            result.Message += user + ", ";
                        }
                        result.Message += ")";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success    = false;
                result.Error      = ex.Message;
                result.StackTrace = ex.StackTrace;
            }
            finally
            {
                result.UserName      = User.Identity.Name;
                result.WasAuthorised = User.Identity.IsAuthenticated;
            }
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
        public HttpResponseMessage HardDeleteNextUsers(Newtonsoft.Json.Linq.JObject requestJson)
        {
            UserResult result = new UserResult();
            try
            {
                if (requestJson == null) throw new ArgumentNullException("requestJson");
                bool testRun = false; int actionNumber = 0; bool useFastDelete = false;
                bool.TryParse(requestJson["testRun"].ToString(), out testRun);
                int.TryParse(requestJson["actionNumber"].ToString(), out actionNumber);
                bool.TryParse(requestJson["useFastDelete"].ToString(), out useFastDelete);
                //return a summary of the number of deleted users
                if (this.PortalSettings == null) throw new ArgumentNullException("PortalSettings object");
                int portalId = this.PortalSettings.PortalId;
                string message = null; int deletedUserCount = -1; int remainingUsersCount = -1; List<string> elapsedTimes;
                //call the method which actually performs the batch delete
                result.Success = UserDeleteController.HardDeleteUsers(testRun, actionNumber, portalId, useFastDelete, out deletedUserCount, out remainingUsersCount, out message, out elapsedTimes);
                result.Message = message;
#if (DEBUG)
                //in debug mode, output an array of call times
                result.ElapsedTimes = elapsedTimes.ToArray();
#endif
                if (result.Success)
                {
                    result.UsersAffected = deletedUserCount;
                    result.UsersRemaining = remainingUsersCount;
                }
                else
                {
                    result.Message = "Failed : no changes made";
                    result.Error = message;
                    result.UsersAffected = 0;
                    result.UsersRemaining = remainingUsersCount;
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Error = ex.Message;
                result.StackTrace = ex.StackTrace;
            }
            finally
            {
                result.UserName = User.Identity.Name;
                result.WasAuthorised = User.Identity.IsAuthenticated;
            }
            return Request.CreateResponse(HttpStatusCode.OK, result);
        }