/// <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!"))); }
/// <summary> /// Retrieves groups from the database associated with the current user in session. /// </summary> private void retrieveGroups() { if (null != _currentUser) { List<GroupDAO> ownedGroups = new List<GroupDAO>(); List<GroupDAO> moderatedGroups = new List<GroupDAO>(); List<GroupDAO> userIsInGroups = new List<GroupDAO>(); try { IDBController controller = new SqlController(); ownedGroups = controller.GetGroupsUserIsOwnerOf(_currentUser.UserID); moderatedGroups = controller.GetGroupsUserIsModeratorOf(_currentUser.UserID); userIsInGroups = controller.GetGroupsUserIsMemberOf(_currentUser.UserID); } catch (SqlException) { groupsUserOwns.Text = "<li>An error occurred gathering group information. Please try again later.</li>"; return; } printGroupsToPage(ownedGroups, groupsUserOwns, @"<li>You do not own any groups. Press ""Create Group"" to make a new one!</li>"); printGroupsToPage(moderatedGroups, groupsUserModerates, "<li>You are not the moderator of any groups.</li>"); printGroupsToPage(userIsInGroups, groupsUserIsIn, "<li>You are not a user of any groups.</li>"); } }
/// <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!"))); }