/// <summary> /// Handles the ItemDataBound event of the rptQueues control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param> protected void rpQueues_ItemDataBound(object sender, RepeaterItemEventArgs e) { switch (e.Item.ItemType) { case ListItemType.AlternatingItem: case ListItemType.Item: SupportQueueEntity currentSupportQueue = (SupportQueueEntity)e.Item.DataItem; // get the threads in the queue and bind it to the repeater. If there are no threads, show the placeholder and hide the repeater. DataView threadsInQueue = SupportQueueGuiHelper.GetAllThreadsInSupportQueueAsDataView( SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum), currentSupportQueue.QueueID); if (threadsInQueue.Count > 0) { // there is data, bind it to the repeater // Find repeater control in this item Repeater rpThreads = (Repeater)e.Item.FindControl("rpThreads"); // bind it rpThreads.DataSource = threadsInQueue; rpThreads.DataBind(); } else { // no data, show the placeholder PlaceHolder noDataText = (PlaceHolder)e.Item.FindControl("phNoDataText"); noDataText.Visible = true; } break; } }
protected void btnSet_Click(object sender, EventArgs e) { if (!_userMayManageSupportQueueContents) { return; } // move this thread to a support queue. // check the selected ID to see if it is the same as the current Queue. If so, ignore, otherwise set the queue. int selectedQueueID = HnDGeneralUtils.TryConvertToInt(cbxSupportQueues.SelectedValue); SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(_thread.ThreadID); // now set the queue if: // a) the thread isn't in a queue and the selected queueID > 0 (so not None) // b) the thread is in a queue and the selected queueuID isn't the id of the queue containing the thread if (((containingQueue == null) && (selectedQueueID != -1)) || ((containingQueue != null) && (containingQueue.QueueID != selectedQueueID))) { // Set the queue. if the new queue is -1, remove from queue. if (selectedQueueID > 0) { SupportQueueManager.AddThreadToQueue(_thread.ThreadID, selectedQueueID, SessionAdapter.GetUserID(), null); } else { SupportQueueManager.RemoveThreadFromQueue(_thread.ThreadID, null); } } // done redirect to this page to refresh. Response.Redirect("Messages.aspx?ThreadID=" + _thread.ThreadID + "&StartAtMessage=" + _startMessageNo); }
/// <summary>Creates a new, empty SupportQueueEntity object.</summary> /// <returns>A new, empty SupportQueueEntity object.</returns> public override IEntity Create() { IEntity toReturn = new SupportQueueEntity(); // __LLBLGENPRO_USER_CODE_REGION_START CreateNewSupportQueue // __LLBLGENPRO_USER_CODE_REGION_END return(toReturn); }
/// <summary> /// Creates a new support queue. /// </summary> /// <param name="queueName">Name of the queue.</param> /// <param name="queueDescription">The queue description.</param> /// <param name="orderNo">The order no.</param> /// <returns>true if succeeded, false otherwise</returns> public static bool CreateNewSupportQueue(string queueName, string queueDescription, short orderNo) { SupportQueueEntity toInsert = new SupportQueueEntity(); toInsert.QueueDescription = queueDescription; toInsert.QueueName = queueName; toInsert.OrderNo = orderNo; return(toInsert.Save()); }
/// <summary> /// Updates the user/forum/thread statistics after a message insert. Also makes sure if the thread isn't in a queue and the forum has a default support /// queue that the thread is added to that queue /// </summary> /// <param name="threadID">The thread ID.</param> /// <param name="userID">The user ID.</param> /// <param name="transactionToUse">The transaction to use.</param> /// <param name="postingDate">The posting date.</param> /// <param name="addToQueueIfRequired">if set to true, the thread will be added to the default queue of the forum the thread is in, if the forum /// has a default support queue and the thread isn't already in a queue.</param> /// <remarks>Leaves the passed in transaction open, so it doesn't commit/rollback, it just performs a set of actions inside the /// passed in transaction.</remarks> internal static void UpdateStatisticsAfterMessageInsert(int threadID, int userID, Transaction transactionToUse, DateTime postingDate, bool addToQueueIfRequired, bool subscribeToThread) { // user statistics UserEntity userUpdater = new UserEntity(); // set the amountofpostings field to an expression so it will be increased with 1. userUpdater.Fields[(int)UserFieldIndex.AmountOfPostings].ExpressionToApply = (UserFields.AmountOfPostings + 1); UserCollection users = new UserCollection(); transactionToUse.Add(users); users.UpdateMulti(userUpdater, (UserFields.UserID == userID)); // update directly on the DB. // thread statistics ThreadEntity threadUpdater = new ThreadEntity(); threadUpdater.ThreadLastPostingDate = postingDate; threadUpdater.MarkedAsDone = false; ThreadCollection threads = new ThreadCollection(); transactionToUse.Add(threads); threads.UpdateMulti(threadUpdater, (ThreadFields.ThreadID == threadID)); // forum statistics. Load the forum from the DB, as we need it later on. Use a fieldcompareset predicate to fetch the forum as we don't know the // forumID as we haven't fetched the thread ForumCollection forums = new ForumCollection(); transactionToUse.Add(forums); // use a fieldcompare set predicate to select the forumid based on the thread. This filter is equal to // WHERE ForumID == (SELECT ForumID FROM Thread WHERE ThreadID=@ThreadID) var forumFilter = new FieldCompareSetPredicate( ForumFields.ForumID, ThreadFields.ForumID, SetOperator.Equal, (ThreadFields.ThreadID == threadID)); forums.GetMulti(forumFilter); ForumEntity containingForum = null; if(forums.Count>0) { // forum found. There's just one. containingForum = forums[0]; containingForum.ForumLastPostingDate = postingDate; // save the forum. Just save the collection forums.SaveMulti(); } if(addToQueueIfRequired) { // If the thread involved isn't in a queue, place it in the default queue of the forum (if applicable) SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID, transactionToUse); if((containingQueue == null) && (containingForum != null) && (containingForum.DefaultSupportQueueID.HasValue)) { // not in a queue, and the forum has a default queue. Add the thread to the queue of the forum SupportQueueManager.AddThreadToQueue(threadID, containingForum.DefaultSupportQueueID.Value, userID, transactionToUse); } } //subscribe to thread if indicated if(subscribeToThread) { UserManager.AddThreadToSubscriptions(threadID, userID, transactionToUse); } }
/// <summary> /// Gets the support queue entity with the queue id passed in /// </summary> /// <param name="queueID">The queue ID.</param> /// <returns>the supportqueue entity requested or null if not found.</returns> public static SupportQueueEntity GetSupportQueue(int queueID) { // fetch using the constructor. SupportQueueEntity toReturn = new SupportQueueEntity(queueID); if (toReturn.IsNew) { // not found return(null); } return(toReturn); }
/// <summary> /// Creates a new support queue. /// </summary> /// <param name="newDataDto">the dto with the data for the new queue</param> /// <returns>the id of the new queue or 0 if failed</returns> public static async Task <int> CreateNewSupportQueueAsync(SupportQueueDto newDataDto) { var newSupportQueue = new SupportQueueEntity(); newSupportQueue.UpdateFromSupportQueue(newDataDto); using (var adapter = new DataAccessAdapter()) { var result = await adapter.SaveEntityAsync(newSupportQueue).ConfigureAwait(false); return(result ? newSupportQueue.QueueID : 0); } }
/// <summary> /// Marks the thread as done. /// </summary> /// <param name="threadID">Thread ID.</param> /// <returns></returns> public static bool MarkThreadAsDone(int threadID) { // load the entity from the database ThreadEntity thread = ThreadGuiHelper.GetThread(threadID); if (thread == null) { // not found return(false); } // get the support queue the thread is in (if any) SupportQueueEntity containingSupportQueue = SupportQueueGuiHelper.GetQueueOfThread(threadID); thread.MarkedAsDone = true; // if the thread is in a support queue, the thread has to be removed from that queue. This is a multi-entity action and therefore we've to start a // transaction if that's the case. If not, we can use the easy route and simply save the thread and be done with it. if (containingSupportQueue == null) { // not in a queue, simply save the thread. return(thread.Save()); } // in a queue, so remove from the queue and save the entity. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "MarkThreadDone"); trans.Add(thread); try { // save the thread bool result = thread.Save(); if (result) { // save succeeded, so remove from queue, pass the current transaction to the method so the action takes place inside this transaction. SupportQueueManager.RemoveThreadFromQueue(threadID, trans); } trans.Commit(); return(true); } catch { // rollback transaction trans.Rollback(); throw; } finally { trans.Dispose(); } }
/// <summary> /// Modifies the support queue definition data. /// </summary> /// <param name="queueID">The queue ID of the queue to modify the definition data of.</param> /// <param name="queueName">Name of the queue.</param> /// <param name="queueDescription">The queue description.</param> /// <param name="orderNo">The order no.</param> /// <returns>true if succeeded, false otherwise</returns> public static bool ModifySupportQueue(int queueID, string queueName, string queueDescription, short orderNo) { SupportQueueEntity toModify = SupportQueueGuiHelper.GetSupportQueue(queueID); if (toModify == null) { // not found return(false); } // set the fields, if they're not changed, the field won't be updated in the db. toModify.QueueName = queueName; toModify.QueueDescription = queueDescription; toModify.OrderNo = orderNo; return(toModify.Save()); }
/// <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="System.EventArgs"/> instance containing the event data.</param> private void Page_Load(object sender, System.EventArgs e) { int threadID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ThreadID"]); _thread = ThreadGuiHelper.GetThread(threadID); if (_thread == null) { // not found, return to start page Response.Redirect("default.aspx"); } // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if (!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx"); } _startMessageNo = HnDGeneralUtils.TryConvertToInt(Request.QueryString["StartAtMessage"]); bool highLightSearchResults = (HnDGeneralUtils.TryConvertToInt(Request.QueryString["HighLight"]) == 1); if (!_thread.IsClosed) { if (_thread.IsSticky) { _userMayAddNewMessages = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessageInSticky); } else { _userMayAddNewMessages = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAndEditMessage); } // set show*link class members. These have to be set despite the postback status, as they're used in the repeater. Only set // them to true if the thread isn't closed. They've been initialized to false already. _showEditMessageLink = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditDeleteOtherUsersMessages); _showDeleteMessageLink = _showEditMessageLink; _showQuoteMessageLink = _userMayAddNewMessages; } // show user IP addresses if the user has system admin rights, security admin rights or user admin rights. _showIPAddresses = (SessionAdapter.HasSystemActionRight(ActionRights.SystemManagement) || SessionAdapter.HasSystemActionRight(ActionRights.SecurityManagement) || SessionAdapter.HasSystemActionRight(ActionRights.UserManagement)); // Get the forum entity related to the thread. Use BL class. We could have used Lazy loading, though for the sake of separation, we'll // call into the BL class. ForumEntity forum = CacheManager.GetForum(_thread.ForumID); if (forum == null) { // not found, orphaned thread, return to default page. Response.Redirect("default.aspx"); } _forumAllowsAttachments = (forum.MaxNoOfAttachmentsPerMessage > 0); // check if the user can view this thread. If not, don't continue. if ((_thread.StartedByUserID != SessionAdapter.GetUserID()) && !SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ViewNormalThreadsStartedByOthers) && !_thread.IsSticky) { // can't view this thread, it isn't visible to the user Response.Redirect("default.aspx", true); } _threadStartedByCurrentUser = (_thread.StartedByUserID == SessionAdapter.GetUserID()); _userMayAddAttachments = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAttachment); _userCanCreateThreads = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddNormalThread) || SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddStickyThread); _userMayDoForumSpecificThreadManagement = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ForumSpecificThreadManagement); _userMayDoSystemWideThreadManagement = SessionAdapter.HasSystemActionRight(ActionRights.SystemWideThreadManagement); _userMayEditMemo = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.EditThreadMemo); _userMayMarkThreadAsDone = (SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.FlagThreadAsDone) || _threadStartedByCurrentUser); _userMayManageSupportQueueContents = SessionAdapter.HasSystemActionRight(ActionRights.QueueContentManagement); _userMayDoBasicThreadOperations = (SessionAdapter.GetUserID() > 0); if (!Page.IsPostBack) { plPageListBottom.HighLight = highLightSearchResults; plPageListTop.HighLight = highLightSearchResults; litHighLightLogic.Visible = highLightSearchResults; if (highLightSearchResults) { // make highlighting of search results possible string searchTerms = SessionAdapter.GetSearchTerms(); if (searchTerms == null) { searchTerms = string.Empty; } this.ClientScript.RegisterHiddenField("searchTerms", searchTerms.Replace("AND", "").Replace("OR", "").Replace("and", "").Replace("or", "").Replace("\"", "")); } else { // replace hightlighting scriptblock. this.ClientScript.RegisterClientScriptBlock(this.GetType(), "onLoad", "<script language=\"javascript\" type=\"text/javascript\">function SearchHighlight() {}</script>"); } if (_userMayManageSupportQueueContents) { // fill support queue management area with data. SupportQueueCollection supportQueues = CacheManager.GetAllSupportQueues(); cbxSupportQueues.DataSource = supportQueues; cbxSupportQueues.DataBind(); SupportQueueEntity containingQueue = SupportQueueGuiHelper.GetQueueOfThread(_thread.ThreadID); if (containingQueue != null) { cbxSupportQueues.SelectedValue = containingQueue.QueueID.ToString(); // get claim info SupportQueueThreadEntity supportQueueThreadInfo = SupportQueueGuiHelper.GetSupportQueueThreadInfo(_thread.ThreadID, true); if ((supportQueueThreadInfo != null) && supportQueueThreadInfo.ClaimedByUserID.HasValue) { // claimed by someone lblClaimDate.Text = supportQueueThreadInfo.ClaimedOn.Value.ToString("dd-MMM-yyyy HH:mm.ss", DateTimeFormatInfo.InvariantInfo); lnkClaimerThread.Visible = true; lblNotClaimed.Visible = false; lnkClaimerThread.Text = supportQueueThreadInfo.ClaimedByUser.NickName; lnkClaimerThread.NavigateUrl += supportQueueThreadInfo.ClaimedByUserID.ToString(); btnClaim.Visible = false; btnRelease.Visible = true; } else { // not claimed lblClaimDate.Text = string.Empty; btnClaim.Visible = true; btnRelease.Visible = false; } } } phSupportQueueManagement.Visible = _userMayManageSupportQueueContents; if ((_thread.Memo.Length > 0) && _userMayEditMemo) { // convert memo contents to HTML so it's displayed above the thread. string parserLog, messageTextXml; bool errorsOccured = false; string memoAsHTML = TextParser.TransformUBBMessageStringToHTML(_thread.Memo, ApplicationAdapter.GetParserData(), out parserLog, out errorsOccured, out messageTextXml); lblMemo.Text = memoAsHTML; } phMemo.Visible = _userMayEditMemo; bool isBookmarked = UserGuiHelper.CheckIfThreadIsAlreadyBookmarked(SessionAdapter.GetUserID(), threadID); bool isSubscribed = UserGuiHelper.CheckIfThreadIsAlreadySubscribed(SessionAdapter.GetUserID(), threadID); btnBookmarkThread.Visible = !isBookmarked && _userMayDoBasicThreadOperations; btnUnbookmarkThread.Visible = isBookmarked && _userMayDoBasicThreadOperations; bool sendReplyNotifications = CacheManager.GetSystemData().SendReplyNotifications; btnSubscribeToThread.Visible = !isSubscribed && _userMayDoBasicThreadOperations && sendReplyNotifications; btnUnsubscribeFromThread.Visible = isSubscribed && _userMayDoBasicThreadOperations && sendReplyNotifications; // fill the page's content lnkThreads.Text = HttpUtility.HtmlEncode(forum.ForumName); lnkThreads.NavigateUrl += "?ForumID=" + _thread.ForumID; lblForumName_Header.Text = forum.ForumName; lblSectionName.Text = CacheManager.GetSectionName(forum.SectionID); // Check if the current user is allowed to add new messages to the thread. // these controls are not visible by default, show them if necessary if (_userMayDoForumSpecificThreadManagement || _userMayDoSystemWideThreadManagement) { if (!_thread.IsClosed && _userMayAddNewMessages) { lnkCloseThread.Visible = true; lnkCloseThread.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; } lnkEditThreadProperties.Visible = true; lnkEditThreadProperties.NavigateUrl += "?ThreadID=" + threadID; } if (_userMayDoSystemWideThreadManagement) { lnkMoveThread.Visible = true; lnkMoveThread.NavigateUrl += "?ThreadID=" + threadID; lnkDeleteThread.Visible = true; lnkDeleteThread.NavigateUrl += "?ThreadID=" + threadID; } btnThreadDone.Visible = _thread.MarkedAsDone; btnThreadNotDone.Visible = !_thread.MarkedAsDone; btnThreadDone.Enabled = _userMayMarkThreadAsDone; btnThreadNotDone.Enabled = _userMayMarkThreadAsDone; if (_userMayEditMemo) { lnkEditMemo.Visible = true; lnkEditMemo.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; } // These controls are visible by default. Hide them when the user can't create threads on this forum if (_userCanCreateThreads) { lnkNewThreadBottom.NavigateUrl += "?ForumID=" + _thread.ForumID + "&StartAtMessage=" + _startMessageNo; lnkNewThreadTop.NavigateUrl += "?ForumID=" + _thread.ForumID + "&StartAtMessage=" + _startMessageNo; } else { lnkNewThreadBottom.Visible = false; lnkNewThreadTop.Visible = false; } if (_userMayAddNewMessages) { lnkNewMessageBottom.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; lnkNewMessageTop.NavigateUrl += "?ThreadID=" + threadID + "&StartAtMessage=" + _startMessageNo; } else { lnkNewMessageBottom.Visible = false; lnkNewMessageTop.Visible = false; } lblSeparatorTop.Visible = (_userMayAddNewMessages && _userCanCreateThreads); lblSeparatorBottom.Visible = (_userMayAddNewMessages && _userCanCreateThreads); // The amount of postings in this thread are in the dataview row, which should contain just 1 row. int maxAmountMessagesPerPage = SessionAdapter.GetUserDefaultNumberOfMessagesPerPage(); int amountOfMessages = ThreadGuiHelper.GetTotalNumberOfMessagesInThread(threadID); int amountOfPages = ((amountOfMessages - 1) / maxAmountMessagesPerPage) + 1; int currentPageNo = (_startMessageNo / maxAmountMessagesPerPage) + 1; lblCurrentPage.Text = currentPageNo.ToString(); lblTotalPages.Text = amountOfPages.ToString(); lnkPrintThread.NavigateUrl += "?ThreadID=" + threadID; plPageListBottom.AmountMessages = amountOfMessages; plPageListBottom.StartMessageNo = _startMessageNo; plPageListBottom.ThreadID = threadID; plPageListTop.AmountMessages = amountOfMessages; plPageListTop.StartMessageNo = _startMessageNo; plPageListTop.ThreadID = threadID; // Get messages and bind it to the repeater control. Use the startmessage to get only the message visible on the current page. MessagesInThreadTypedList messages = ThreadGuiHelper.GetAllMessagesInThreadAsTypedList(threadID, currentPageNo, maxAmountMessagesPerPage); rptMessages.DataSource = messages; rptMessages.DataBind(); } }