/// <summary>
    /// Updates the group's metadata in the database 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void submitPluginsButton_Click(object sender, EventArgs e)
    {
        bool isMod = false;
        string groupTag = Request.QueryString["grouptag"];
        SqlController control = new SqlController();
        GroupDAO group = control.RetrieveGroup(groupTag);
        List<GroupDAO> groupList = control.GetGroupsUserIsModeratorOf(_currentUser.UserID);
        foreach (GroupDAO x in groupList)
        {
            if (x.GroupID == group.GroupID)
            {
                isMod = true;
            }
        }

        if (_currentGroup.Owner.UserID != _currentUser.UserID && !isMod)
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit plugins in groups you do not own.")));
            return;
        }

        try
        {
            IDBController controller = new SqlController();

            _currentGroup.EnabledPlugins = ParseFromTextArea(enabledPlugins);

            control.UpdateGroupPlugins(_currentGroup);

        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManagePlugins.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManagePlugins.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return;
        }

        Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&success={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Plugins successfully updated!")));
    }
 private void GetGroupData()
 {
     try
     {
         IDBController controller = new SqlController();
         _currentGroup = controller.RetrieveGroup(Request["grouptag"]);
     }
     catch (ArgumentNullException)
     {
         // Shouldn't happen
     }
     catch (CouldNotFindException)
     {
         Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"An unknown error occurred. Please try again soon.")));
         return;
     }
     catch (SqlException ex)
     {
         Logger.LogMessage("ManageGroup.aspx.cs: " + ex.Message, LoggerLevel.SEVERE);
         Response.Redirect(string.Format("ManagePlugins.aspx?error={0}", HttpUtility.UrlEncode("An unknown error occurred. Please try again soon.")));
         return;
     }
 }
    /// <summary>
    /// Updates the group's metadata in the database 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void UpdateGroupMetadata_Click(object sender, EventArgs e)
    {
        bool isMod = false;
        string groupTag = Request.QueryString["grouptag"];
        SqlController control = new SqlController();
        GroupDAO group = control.RetrieveGroup(groupTag);
        List<GroupDAO> groupList = control.GetGroupsUserIsModeratorOf(_currentUser.UserID);
        foreach (GroupDAO x in groupList)
        {
            if (x.GroupID == group.GroupID)
            {
                isMod = true;
            }
        }

        if (_currentGroup.Owner.UserID != _currentUser.UserID && !isMod)
        {
            Response.Redirect(string.Format(@"Index.aspx?error={0}", HttpUtility.UrlEncode(@"You cannot edit groups you do not own.")));
            return;
        }

        // Check that they are not updating to empty values
        if (string.IsNullOrWhiteSpace(groupNameBox.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group name to be empty or whitespace.")));
            groupNameBox.Focus();
            return;
        }
        else if (string.IsNullOrWhiteSpace(groupTagBox.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group tag to be empty or whitespace.")));
            groupTagBox.Focus();
            return;
        }
        else if (string.IsNullOrWhiteSpace(groupDescriptionBox.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group description to be empty or whitespace.")));
            groupDescriptionBox.Focus();
            return;
        }
        else if (string.IsNullOrWhiteSpace(groupOwner.Text))
        {
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("Cannot update group owner to be empty or whitespace.")));
            groupOwner.Focus();
            return;
        }

        try
        {
            IDBController controller = new SqlController();
            // Check first that the group tag isn't already being used in the database by a different group
            if (!controller.GroupExists(groupTagBox.Text, _currentGroup.GroupID))
            {
                // If ok, set the current groupDAO reference to the group tag and update the database
                _currentGroup.Name = groupNameBox.Text;
                _currentGroup.GroupTag = groupTagBox.Text;
                _currentGroup.Description = groupDescriptionBox.Text;

                controller.UpdateGroupMetadata(_currentGroup);

                _currentGroup.Moderators = ParseUsersFromTextArea(groupModerators);
                _currentGroup.Users = ParseUsersFromTextArea(groupUsers);

                controller.UpdateGroup(_currentGroup);
            }
            else
            {
                // Tell the user they can't use the group tag
                Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                    HttpUtility.UrlEncode(_currentGroup.GroupTag),
                    HttpUtility.UrlEncode(string.Format(@"A group with grouptag ""{0}"" already exists.", HttpUtility.HtmlEncode(groupTagBox.Text)))));
                return;
            }
        }
        catch (ArgumentNullException)
        {
            // Shouldn't happen
        }
        catch (CouldNotFindException)
        {
            // Shouldn't happen
        }
        catch (SqlException ex)
        {
            Logger.LogMessage("ManageGroup.aspx: " + ex.Message, LoggerLevel.SEVERE);
            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("An error occurred connecting to the server. Please try again soon.")));
            return;
        }

        if (usersNotFound.Count > 0)
        {
            StringBuilder builder = new StringBuilder();
            foreach (string user in usersNotFound)
            {
                builder.Append(user + " ");
            }

            Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&error={1}",
                HttpUtility.UrlEncode(_currentGroup.GroupTag),
                HttpUtility.UrlEncode("The following users were not found in the database and were not added to the group: " + builder.ToString())));
        }

        Response.Redirect(string.Format("ManageGroup.aspx?grouptag={0}&success={1}",
            HttpUtility.UrlEncode(_currentGroup.GroupTag),
            HttpUtility.UrlEncode("The group information was updated successfully!")));
    }