/// <summary> /// Creates a new forum in the system, and locates this forum in the section iSectionID. /// </summary> /// <param name="sectionID">The section ID.</param> /// <param name="forumName">Name of the forum.</param> /// <param name="forumDescription">The forum description.</param> /// <param name="hasRSSFeed">True if the forum has an RSS feed.</param> /// <param name="defaultSupportQueueID">The ID of the default support queue for this forum. Can be null.</param> /// <param name="defaultThreadListInterval">The default thread list interval.</param> /// <param name="orderNo">The order no for the section. Sections are sorted ascending on orderno.</param> /// <param name="maxAttachmentSize">Max. size of an attachment.</param> /// <param name="maxNoOfAttachmentsPerMessage">The max no of attachments per message.</param> /// <param name="newThreadWelcomeText">The new thread welcome text, as shown when a new thread is created. Can be null.</param> /// <param name="newThreadWelcomeTextAsHTML">The new thread welcome text as HTML, is null when newThreadWelcomeText is null or empty.</param> /// <returns> /// ForumID of new forum or 0 if something went wrong. /// </returns> public static int CreateNewForum(int sectionID, string forumName, string forumDescription, bool hasRSSFeed, int? defaultSupportQueueID, int defaultThreadListInterval, short orderNo, int maxAttachmentSize, short maxNoOfAttachmentsPerMessage, string newThreadWelcomeText, string newThreadWelcomeTextAsHTML) { ForumEntity newForum = new ForumEntity(); newForum.SectionID = sectionID; newForum.ForumDescription = forumDescription; newForum.ForumName = forumName; newForum.HasRSSFeed = hasRSSFeed; newForum.DefaultSupportQueueID = defaultSupportQueueID; newForum.DefaultThreadListInterval = Convert.ToByte(defaultThreadListInterval); newForum.OrderNo = orderNo; newForum.MaxAttachmentSize = maxAttachmentSize; newForum.MaxNoOfAttachmentsPerMessage = maxNoOfAttachmentsPerMessage; newForum.NewThreadWelcomeText = newThreadWelcomeText; newForum.NewThreadWelcomeTextAsHTML = newThreadWelcomeTextAsHTML; bool result = newForum.Save(); if(result) { // succeeded return newForum.ForumID; } else { return 0; } }
/// <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) { _siteName = HttpUtility.HtmlEncode(ApplicationAdapter.GetSiteName()); int forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]); _forum = CacheManager.GetForum(forumID); if((_forum != null) && _forum.HasRSSFeed) { _forumURL = "http://" + Request.Url.Host + ApplicationAdapter.GetVirtualRoot() + String.Format(@"Threads.aspx?ForumID={0}", forumID); // get the messages ForumMessagesTypedList messages = ForumGuiHelper.GetLastPostedMessagesInForum(10, forumID); rptRSS.DataSource = messages; rptRSS.DataBind(); Response.Cache.SetExpires(DateTime.Now.AddDays(7)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.VaryByParams["ForumID"] = true; Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(Validate), null); } }
/// <summary> /// Deletes the support queue with the ID specified. /// </summary> /// <param name="queueID">The queue ID of the queue to delete.</param> /// <returns>true if succeeded, false otherwise</returns> /// <remarks>All threads in the queue are automatically de-queued and not in a queue anymore. The Default support queue /// for forums which have this queue as the default support queue is reset to null.</remarks> public static bool DeleteSupportQueue(int queueID) { // we'll do several actions in one atomic transaction, so start a transaction first. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "DeleteSupportQ"); try { // first reset all the FKs in Forum to NULL if they point to this queue. ForumEntity forumUpdater = new ForumEntity(); // set the field to NULL. This is a nullable field, so we can just set the field to 'null', thanks to nullable types. forumUpdater.DefaultSupportQueueID = null; // update the entities directly in the db, use a forum collection for that ForumCollection forums = new ForumCollection(); trans.Add(forums); // specify a filter that only the forums which have this queue as the default queue are updated and have their FK field set to NULL. forums.UpdateMulti(forumUpdater, (ForumFields.DefaultSupportQueueID == queueID)); // delete all SupportQueueThread entities which refer to this queue. This will make all threads which are in this queue become queue-less. SupportQueueThreadCollection supportQueueThreads = new SupportQueueThreadCollection(); trans.Add(supportQueueThreads); // delete them directly from the db. supportQueueThreads.DeleteMulti((SupportQueueThreadFields.QueueID == queueID)); // it's now time to delete the actual supportqueue entity. SupportQueueCollection supportQueues = new SupportQueueCollection(); trans.Add(supportQueues); // delete it directly from the db. int numberOfQueuesDeleted = supportQueues.DeleteMulti((SupportQueueFields.QueueID == queueID)); // done so commit the transaction. trans.Commit(); return (numberOfQueuesDeleted > 0); } catch { // first roll back the transaction trans.Rollback(); // then bubble up the exception throw; } finally { trans.Dispose(); } }
/// <summary> /// Marks the thread as un-done, and add it to the default queue of the forum. /// </summary> /// <param name="threadID">Thread ID</param> /// <returns></returns> public static bool UnMarkThreadAsDone(int threadID, int userID) { // load the entity from the database ThreadEntity thread = ThreadGuiHelper.GetThread(threadID); if (thread == null) { // not found return false; } thread.MarkedAsDone = false; ForumEntity forum = new ForumEntity(thread.ForumID); // Save the thread and add it to the default queue of the forum. Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "MarkThreadUnDone"); trans.Add(thread); try { thread.Save(); if ((forum.Fields.State == EntityState.Fetched) && (forum.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, forum.DefaultSupportQueueID.Value, userID, trans); } trans.Commit(); return true; } catch { // rollback transaction trans.Rollback(); throw; } finally { trans.Dispose(); } }
/// <summary> Removes the sync logic for member _forum</summary> /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param> /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param> private void DesetupSyncForum(bool signalRelatedEntity, bool resetFKFields) { this.PerformDesetupSyncRelatedEntity( _forum, new PropertyChangedEventHandler( OnForumPropertyChanged ), "Forum", SD.HnD.DAL.RelationClasses.StaticForumRoleForumActionRightRelations.ForumEntityUsingForumIDStatic, true, signalRelatedEntity, "ForumRoleForumActionRights", resetFKFields, new int[] { (int)ForumRoleForumActionRightFieldIndex.ForumID } ); _forum = null; }
/// <summary> Retrieves the related entity of type 'ForumEntity', using a relation of type 'n:1'</summary> /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param> /// <returns>A fetched entity of type 'ForumEntity' which is related to this entity.</returns> public virtual ForumEntity GetSingleForum(bool forceFetch) { if( ( !_alreadyFetchedForum || forceFetch || _alwaysFetchForum) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode) { bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.ForumEntityUsingForumID); ForumEntity newEntity = new ForumEntity(); bool fetchResult = false; if(performLazyLoading) { AddToTransactionIfNecessary(newEntity); fetchResult = newEntity.FetchUsingPK(this.ForumID); } if(fetchResult) { newEntity = (ForumEntity)GetFromActiveContext(newEntity); } else { if(!_forumReturnsNewIfNotFound) { RemoveFromTransactionIfNecessary(newEntity); newEntity = null; } } this.Forum = newEntity; _alreadyFetchedForum = fetchResult; } return _forum; }
/// <summary>Private CTor for deserialization</summary> /// <param name="info"></param> /// <param name="context"></param> protected ForumRoleForumActionRightEntityBase(SerializationInfo info, StreamingContext context) : base(info, context) { _actionRight = (ActionRightEntity)info.GetValue("_actionRight", typeof(ActionRightEntity)); if(_actionRight!=null) { _actionRight.AfterSave+=new EventHandler(OnEntityAfterSave); } _actionRightReturnsNewIfNotFound = info.GetBoolean("_actionRightReturnsNewIfNotFound"); _alwaysFetchActionRight = info.GetBoolean("_alwaysFetchActionRight"); _alreadyFetchedActionRight = info.GetBoolean("_alreadyFetchedActionRight"); _forum = (ForumEntity)info.GetValue("_forum", typeof(ForumEntity)); if(_forum!=null) { _forum.AfterSave+=new EventHandler(OnEntityAfterSave); } _forumReturnsNewIfNotFound = info.GetBoolean("_forumReturnsNewIfNotFound"); _alwaysFetchForum = info.GetBoolean("_alwaysFetchForum"); _alreadyFetchedForum = info.GetBoolean("_alreadyFetchedForum"); _role = (RoleEntity)info.GetValue("_role", typeof(RoleEntity)); if(_role!=null) { _role.AfterSave+=new EventHandler(OnEntityAfterSave); } _roleReturnsNewIfNotFound = info.GetBoolean("_roleReturnsNewIfNotFound"); _alwaysFetchRole = info.GetBoolean("_alwaysFetchRole"); _alreadyFetchedRole = info.GetBoolean("_alreadyFetchedRole"); this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance()); // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }
/// <summary> setups the sync logic for member _forum</summary> /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param> private void SetupSyncForum(IEntityCore relatedEntity) { if(_forum!=relatedEntity) { DesetupSyncForum(true, true); _forum = (ForumEntity)relatedEntity; this.PerformSetupSyncRelatedEntity( _forum, new PropertyChangedEventHandler( OnForumPropertyChanged ), "Forum", SD.HnD.DAL.RelationClasses.StaticForumRoleForumActionRightRelations.ForumEntityUsingForumIDStatic, true, ref _alreadyFetchedForum, new string[] { } ); } }
protected void Page_Load(object sender, EventArgs e) { int messageID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["MessageID"]); _message = MessageGuiHelper.GetMessage(messageID); if(_message == null) { // not found Response.Redirect("default.aspx", true); } _sourceType = HnDGeneralUtils.TryConvertToInt(Request.QueryString["SourceType"]); switch(_sourceType) { case 1: // new message, or message view, for now no action needed break; case 2: // new thread, for now no action needed break; default: // unknown, redirect Response.Redirect("default.aspx", true); break; } // We could have used Lazy loading here, but for the sake of separation, we use the BL method. _thread = ThreadGuiHelper.GetThread(_message.ThreadID); if(_thread == null) { // not found. Orphaned message. Response.Redirect("default.aspx", true); } _forum = CacheManager.GetForum(_thread.ForumID); if(_forum == null) { // not found. Response.Redirect("default.aspx", true); } // check if this forum accepts attachments. if(_forum.MaxNoOfAttachmentsPerMessage <= 0) { // no, so no right to be here nor is the user here via a legitimate route. Response.Redirect("default.aspx", true); } // Check credentials bool userHasAccess = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AccessForum); if(!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx", true); } // 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); } // Check if the current user is allowed to manage attachments of this message, and other rights. _userMayManageAttachments = ((_message.PostedByUserID==SessionAdapter.GetUserID())|| SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ManageOtherUsersAttachments)); _userCanAddAttachments = (((_message.PostedByUserID==SessionAdapter.GetUserID()) || SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ManageOtherUsersAttachments)) && SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.AddAttachment)); _userCanApproveAttachments = SessionAdapter.CanPerformForumActionRight(_thread.ForumID, ActionRights.ApproveAttachment); phAttachmentLimits.Visible = _userMayManageAttachments; if(!Page.IsPostBack) { // fill the page's content lnkThreads.Text = HttpUtility.HtmlEncode(_forum.ForumName); lnkThreads.NavigateUrl += "?ForumID=" + _thread.ForumID; lblSectionName.Text = CacheManager.GetSectionName(_forum.SectionID); lnkMessages.NavigateUrl += _message.ThreadID; lnkMessages.Text = HttpUtility.HtmlEncode(_thread.Subject); lblMaxFileSize.Text = String.Format("{0} KB", _forum.MaxAttachmentSize); lblMaxNoOfAttachmentsPerMessage.Text = _forum.MaxNoOfAttachmentsPerMessage.ToString(); lnkMessage.Text += messageID.ToString(); lnkMessage.NavigateUrl += String.Format("MessageID={0}&ThreadID={1}", messageID, _thread.ThreadID); phAddNewAttachment.Visible = _userCanAddAttachments; BindAttachments(); } else { object numberOfAttachments = ViewState["numberOfAttachments"]; if(numberOfAttachments != null) { _numberOfAttachments = (int)numberOfAttachments; } } }
/// <summary> /// Returns a ForumEntity of the given forum /// </summary> /// <param name="forumID">ForumID of forum which data should be read</param> /// <returns>forum entity with the data requested, or null if not found</returns> public static ForumEntity GetForum(int forumID) { ForumEntity toReturn = new ForumEntity(forumID); if(toReturn.Fields.State!=EntityState.Fetched) { return null; } return toReturn; }
/// <summary>Creates a new, empty ForumEntity object.</summary> /// <returns>A new, empty ForumEntity object.</returns> public override IEntity Create() { IEntity toReturn = new ForumEntity(); // __LLBLGENPRO_USER_CODE_REGION_START CreateNewForum // __LLBLGENPRO_USER_CODE_REGION_END return toReturn; }
private void Page_Load(object sender, System.EventArgs e) { int forumID = HnDGeneralUtils.TryConvertToInt(Request.QueryString["ForumID"]); _forum = CacheManager.GetForum(forumID); if(_forum == null) { // not found Response.Redirect("default.aspx", true); } bool userHasAccess = SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AccessForum); if(!userHasAccess) { // doesn't have access to this forum. redirect Response.Redirect("default.aspx", true); } _userCanCreateNormalThreads = SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddNormalThread); _userCanCreateStickyThreads = SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddStickyThread); if(!(_userCanCreateNormalThreads || _userCanCreateStickyThreads)) { // doesn't have the right to add new threads to this forum. redirect Response.Redirect("default.aspx", true); } meMessageEditor.ShowAddAttachment = ((_forum.MaxNoOfAttachmentsPerMessage > 0) && SessionAdapter.CanPerformForumActionRight(forumID, ActionRights.AddAttachment)); if(!String.IsNullOrEmpty(_forum.NewThreadWelcomeTextAsHTML)) { phWelcomeText.Visible = true; litWelcomeText.Text = _forum.NewThreadWelcomeTextAsHTML; } if(!Page.IsPostBack) { // fill the page's content lnkThreads.Text = HttpUtility.HtmlEncode(_forum.ForumName); lnkThreads.NavigateUrl += "?ForumID=" + forumID; meMessageEditor.ForumName = _forum.ForumName; meMessageEditor.ForumDescription = HttpUtility.HtmlEncode(_forum.ForumDescription); meMessageEditor.CanBeSticky = _userCanCreateStickyThreads; meMessageEditor.CanBeNormal = _userCanCreateNormalThreads; meMessageEditor.IsThreadStart = true; lblSectionName.Text = CacheManager.GetSectionName(_forum.SectionID); } }
/// <summary>Private CTor for deserialization</summary> /// <param name="info"></param> /// <param name="context"></param> protected ThreadEntityBase(SerializationInfo info, StreamingContext context) : base(info, context) { _auditDataThreadRelated = (SD.HnD.DAL.CollectionClasses.AuditDataThreadRelatedCollection)info.GetValue("_auditDataThreadRelated", typeof(SD.HnD.DAL.CollectionClasses.AuditDataThreadRelatedCollection)); _alwaysFetchAuditDataThreadRelated = info.GetBoolean("_alwaysFetchAuditDataThreadRelated"); _alreadyFetchedAuditDataThreadRelated = info.GetBoolean("_alreadyFetchedAuditDataThreadRelated"); _presentInBookmarks = (SD.HnD.DAL.CollectionClasses.BookmarkCollection)info.GetValue("_presentInBookmarks", typeof(SD.HnD.DAL.CollectionClasses.BookmarkCollection)); _alwaysFetchPresentInBookmarks = info.GetBoolean("_alwaysFetchPresentInBookmarks"); _alreadyFetchedPresentInBookmarks = info.GetBoolean("_alreadyFetchedPresentInBookmarks"); _messages = (SD.HnD.DAL.CollectionClasses.MessageCollection)info.GetValue("_messages", typeof(SD.HnD.DAL.CollectionClasses.MessageCollection)); _alwaysFetchMessages = info.GetBoolean("_alwaysFetchMessages"); _alreadyFetchedMessages = info.GetBoolean("_alreadyFetchedMessages"); _threadSubscription = (SD.HnD.DAL.CollectionClasses.ThreadSubscriptionCollection)info.GetValue("_threadSubscription", typeof(SD.HnD.DAL.CollectionClasses.ThreadSubscriptionCollection)); _alwaysFetchThreadSubscription = info.GetBoolean("_alwaysFetchThreadSubscription"); _alreadyFetchedThreadSubscription = info.GetBoolean("_alreadyFetchedThreadSubscription"); _usersWhoBookmarkedThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoBookmarkedThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection)); _alwaysFetchUsersWhoBookmarkedThread = info.GetBoolean("_alwaysFetchUsersWhoBookmarkedThread"); _alreadyFetchedUsersWhoBookmarkedThread = info.GetBoolean("_alreadyFetchedUsersWhoBookmarkedThread"); _usersWhoPostedInThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoPostedInThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection)); _alwaysFetchUsersWhoPostedInThread = info.GetBoolean("_alwaysFetchUsersWhoPostedInThread"); _alreadyFetchedUsersWhoPostedInThread = info.GetBoolean("_alreadyFetchedUsersWhoPostedInThread"); _usersWhoSubscribedThread = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoSubscribedThread", typeof(SD.HnD.DAL.CollectionClasses.UserCollection)); _alwaysFetchUsersWhoSubscribedThread = info.GetBoolean("_alwaysFetchUsersWhoSubscribedThread"); _alreadyFetchedUsersWhoSubscribedThread = info.GetBoolean("_alreadyFetchedUsersWhoSubscribedThread"); _forum = (ForumEntity)info.GetValue("_forum", typeof(ForumEntity)); if(_forum!=null) { _forum.AfterSave+=new EventHandler(OnEntityAfterSave); } _forumReturnsNewIfNotFound = info.GetBoolean("_forumReturnsNewIfNotFound"); _alwaysFetchForum = info.GetBoolean("_alwaysFetchForum"); _alreadyFetchedForum = info.GetBoolean("_alreadyFetchedForum"); _userWhoStartedThread = (UserEntity)info.GetValue("_userWhoStartedThread", typeof(UserEntity)); if(_userWhoStartedThread!=null) { _userWhoStartedThread.AfterSave+=new EventHandler(OnEntityAfterSave); } _userWhoStartedThreadReturnsNewIfNotFound = info.GetBoolean("_userWhoStartedThreadReturnsNewIfNotFound"); _alwaysFetchUserWhoStartedThread = info.GetBoolean("_alwaysFetchUserWhoStartedThread"); _alreadyFetchedUserWhoStartedThread = info.GetBoolean("_alreadyFetchedUserWhoStartedThread"); _supportQueueThread = (SupportQueueThreadEntity)info.GetValue("_supportQueueThread", typeof(SupportQueueThreadEntity)); if(_supportQueueThread!=null) { _supportQueueThread.AfterSave+=new EventHandler(OnEntityAfterSave); } _supportQueueThreadReturnsNewIfNotFound = info.GetBoolean("_supportQueueThreadReturnsNewIfNotFound"); _alwaysFetchSupportQueueThread = info.GetBoolean("_alwaysFetchSupportQueueThread"); _alreadyFetchedSupportQueueThread = info.GetBoolean("_alreadyFetchedSupportQueueThread"); this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance()); // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }