protected void btnSubmit_Click(object sender, EventArgs e) { if (CurrentUserSession == null || (CurrentGroupMember == null && !CurrentUserSession.IsAdmin()) || (CurrentGroupMember != null && CurrentGroupMember.Type != GroupMember.eType.Admin && CurrentGroupMember.Type != GroupMember.eType.Moderator)) return; bool kicked = false; GroupPost groupPost = GroupPost.Fetch(PostID); if (groupPost != null) { if (!cbKickMember.Checked && !cbBanMember.Checked && cbWarn.Checked) { if (ddWarnExpirationDate.SelectedValue != "-1") { GroupMember groupMember = GroupMember.Fetch(GroupID, groupPost.Username); if (groupMember != null) { groupMember.IsWarned = true; groupMember.WarnReason = txtWarnReason.Text.Trim(); groupMember.WarnExpirationDate = ddWarnExpirationDate.SelectedValue == "0" ? DateTime.Now.AddYears(5) : DateTime.Now.AddDays( Double.Parse(ddWarnExpirationDate.SelectedValue)); groupMember.Save(); User user = null; try { user = User.Load(groupMember.Username); MiscTemplates.WarnGroupMemberMessage warnGroupMemberMessageTemplate = new MiscTemplates.WarnGroupMemberMessage(user.LanguageId); Message.Send(CurrentUserSession.Username, user.Username, warnGroupMemberMessageTemplate.GetFormattedMessage(CurrentGroup.Name, groupMember.WarnReason), 0); } catch (NotFoundException){} } } else { lblError.Text = Lang.Trans("Please select a period."); return; } } if (cbBanMember.Checked) { if (ddBanPeriod.SelectedValue != "-1") { var groupBan = new GroupBan(GroupID, groupPost.Username); GroupMember.Delete(GroupID, groupPost.Username); // kick member kicked = true; groupBan.Expires = ddBanPeriod.SelectedValue == "0" ? DateTime.Now.AddYears(5) : DateTime.Now.AddDays(Double.Parse(ddBanPeriod.SelectedValue)); groupBan.Save(); } else { lblError.Text = Lang.Trans("Please select a period."); return; } } if (cbKickMember.Checked && !kicked) { GroupMember.Delete(GroupID, groupPost.Username); kicked = true; } if (kicked) { CurrentGroup.ActiveMembers--; CurrentGroup.Save(); } switch (rbList.SelectedValue) { case "deletePost": GroupPost.Delete(PostID); if (GroupTopic.Fetch(CurrentTopic.ID) == null) DeleteNewGroupTopicEvent(CurrentTopic.Username, CurrentTopic.ID); User.AddScore(groupPost.Username, Config.UserScores.DeletedPost, "DeletedPost"); break; case "deleteFromTopic": GroupPost.Delete(TopicID, groupPost.Username); if (GroupTopic.Fetch(CurrentTopic.ID) == null) DeleteNewGroupTopicEvent(CurrentTopic.Username, CurrentTopic.ID); User.AddScore(groupPost.Username, Config.UserScores.DeletedPost, "DeletedPost"); break; case "deleteAll": GroupPost.Delete(groupPost.Username, GroupID); if (GroupTopic.Fetch(CurrentTopic.ID) == null) DeleteNewGroupTopicEvent(CurrentTopic.Username, CurrentTopic.ID); User.AddScore(groupPost.Username, Config.UserScores.DeletedPost, "DeletedPost"); break; } // when group posts has been deleted current group topic should be updated if (rbList.SelectedIndex != -1) { ViewState["CurrentTopic"] = GroupTopic.Fetch(TopicID); } if (CurrentTopic == null) // current topic doesn't exist { Response.Redirect(UrlRewrite.CreateShowGroupTopicsUrl(GroupID.ToString())); return; } GroupTopic groupTopic = GroupTopic.Fetch(CurrentTopic.ID); if (groupTopic == null) { Response.Redirect(UrlRewrite.CreateShowGroupTopicsUrl(GroupID.ToString())); return; } Results = null; mvPosts.SetActiveView(viewPosts); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (CurrentUserSession == null || (CurrentGroupMember == null && !CurrentUserSession.IsAdmin()) || (CurrentGroupMember != null && CurrentGroupMember.Type != GroupMember.eType.Admin && CurrentGroupMember.Type != GroupMember.eType.Moderator)) return; bool kicked = false; GroupPhoto groupPhoto = GroupPhoto.Fetch(GroupPhotoID); if (groupPhoto != null) { if (cbBanMember.Checked) { if (ddBanPeriod.SelectedValue != "-1") { var groupBan = new GroupBan(GroupID, groupPhoto.Username); GroupMember.Delete(GroupID, groupPhoto.Username); // kick member kicked = true; groupBan.Expires = ddBanPeriod.SelectedValue == "0" ? DateTime.Now.AddYears(5) : DateTime.Now.AddDays(Double.Parse(ddBanPeriod.SelectedValue)); groupBan.Save(); } else { lblError.Text = Lang.Trans("Please select a period."); CurrentView = viewDeleteOptions; return; } } if (cbKickMember.Checked && !kicked) { GroupMember.Delete(GroupID, groupPhoto.Username); kicked = true; } if (kicked) { CurrentGroup.ActiveMembers--; CurrentGroup.Save(); } switch (rbList.SelectedValue) { case "deletePhoto": GroupPhoto.Delete(GroupPhotoID); break; case "deleteAll": GroupPhoto.Delete(GroupID, groupPhoto.Username); break; } Results = null; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (CurrentUserSession == null || (CurrentGroupMember == null && !CurrentUserSession.IsAdmin()) || (CurrentGroupMember != null && CurrentGroupMember.Type != GroupMember.eType.Admin)) return; bool kicked = false; if (cbBanMember.Checked) { if (ddBanPeriod.SelectedValue != "-1") { GroupBan groupBan = new GroupBan(GroupID, Username); GroupMember.Delete(GroupID, Username); // kick member kicked = true; if (ddBanPeriod.SelectedValue == "0") // ban forever { groupBan.Expires = DateTime.Now.AddYears(5); } else { groupBan.Expires = DateTime.Now.AddDays(Double.Parse(ddBanPeriod.SelectedValue)); } groupBan.Save(); } else { lblError.Text = Lang.Trans("Please select a period."); return; } } if (cbKickMember.Checked && !kicked) { GroupMember.Delete(GroupID, Username); kicked = true; } if (kicked) { CurrentGroup.ActiveMembers--; CurrentGroup.Save(); } if (cbKickMember.Checked || cbBanMember.Checked && ddBanPeriod.SelectedValue != "-1") { try { User user = User.Load(Username); MiscTemplates.DeleteGroupMemberMessage deleteGroupMemberTemplate = new MiscTemplates.DeleteGroupMemberMessage(user.LanguageId); if (CurrentUserSession != null) { Message msg = new Message(CurrentUserSession.Username, Username); string message = deleteGroupMemberTemplate.Message; message = message.Replace("%%GROUP%%", Parsers.ProcessGroupName(CurrentGroup.Name)); msg.Body = message; msg.Send(); } } catch (NotFoundException) { } } switch (rbList.SelectedValue) { case "deleteGroupPhotos": GroupPhoto.Delete(GroupID, Username); break; case "deleteGroupPosts": GroupPost.Delete(Username); User.AddScore(Username, Config.UserScores.DeletedPost, "DeletedPost"); break; } SearchResults1.Results = null; mvViewGroupMembers.SetActiveView(viewGroupMembers); }
/// <summary> /// Fetches group bans by specified arguments. /// It returns an empty array if there are no group bans in DB by specified arguments. /// If these arguments are null it returns all group bans from DB. /// </summary> /// <param name="id">The id.</param> /// <param name="groupID">The group ID.</param> /// <param name="username">The username.</param> /// <param name="date">The date.</param> /// <returns></returns> private static GroupBan[] Fetch(int? id, int? groupID, string username, DateTime? date) { //using (var conn = Config.DB.Open()) { List<GroupBan> lGroupBans = new List<GroupBan>(); using (var reader = SqlHelper.GetDB().ExecuteReader("FetchGroupBans", id, groupID, username, date)) { while (reader.Read()) { GroupBan groupBan = new GroupBan(); groupBan.id = (int) reader["ID"]; groupBan.groupID = (int) reader["GroupID"]; groupBan.username = (string) reader["Username"]; groupBan.date = (DateTime) reader["Date"]; groupBan.expires = (DateTime) reader["Expires"]; lGroupBans.Add(groupBan); } reader.Close(); } return lGroupBans.ToArray(); } }