/// <summary> /// Adds a new section to the forum system. /// </summary> /// <param name="name">The name.</param> /// <param name="description">The description.</param> /// <param name="orderNo">The order no for the section. Sections are sorted ascending on orderno.</param> /// <returns> /// the SectionID of the new section. Or Zero if failed /// </returns> public static int AddNewSection(string name, string description, short orderNo) { SectionEntity section = new SectionEntity(); // fill the entity fields with data section.SectionName = name; section.SectionDescription = description; section.OrderNo = orderNo; // try to save the entity bool saveResult = section.Save(); // if succeeds return the new ID, else return Zero. if(saveResult == true) { return section.SectionID; } else { return 0; } }
/// <summary> /// Modifies the given section's name and description /// </summary> /// <param name="ID">ID of section to modify</param> /// <param name="name">New name of section</param> /// <param name="description">Description of section</param> /// <param name="orderNo">The order no for the section. Sections are sorted ascending on orderno.</param> /// <returns>True if succeeded, false otherwise</returns> public static bool ModifySection(int ID, string name, string description, short orderNo) { // load the entity from the database SectionEntity section = new SectionEntity(ID); //check if the entity is new (not found in the database), then return false. if(section.IsNew == true) { return false; } // update the fields with new values section.SectionName = name; section.SectionDescription = description; section.OrderNo = orderNo; //try to save the changes return section.Save(); }
/// <summary>Creates a new, empty SectionEntity object.</summary> /// <returns>A new, empty SectionEntity object.</returns> public override IEntity Create() { IEntity toReturn = new SectionEntity(); // __LLBLGENPRO_USER_CODE_REGION_START CreateNewSection // __LLBLGENPRO_USER_CODE_REGION_END return toReturn; }
/// <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 default page 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"); } bool userMayMoveThread = SessionAdapter.HasSystemActionRight(ActionRights.SystemWideThreadManagement); if(!userMayMoveThread) { // doesn't have access to this forum. redirect Response.Redirect("Messages.aspx?ThreadID=" + threadID, 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); } if(!Page.IsPostBack) { // fill the page's content. Bind the known sections SectionCollection sections = CacheManager.GetAllSections(); cbxSections.DataSource = sections; cbxSections.DataBind(); lblThreadSubject.Text = HttpUtility.HtmlEncode(_thread.Subject); ForumEntity forum = CacheManager.GetForum(_thread.ForumID); if(forum == null) { // Orphaned thread Response.Redirect("default.aspx", true); } // pre-select the section the forum is currently in. Do that with an in-memory search through the known sections. SectionEntity toFind = new SectionEntity(); toFind.Fields[(int)SectionFieldIndex.SectionID].ForcedCurrentValueWrite(forum.SectionID); toFind.IsNew=false; int index = sections.IndexOf(toFind); if(index >= 0) { cbxSections.SelectedIndex = index; } } }
/// <summary> /// Gets the section entity of the id passed in /// </summary> /// <param name="sectionID">The section ID.</param> /// <returns>loaded sectionentity or null if not found</returns> public static SectionEntity GetSection(int sectionID) { SectionEntity toReturn = new SectionEntity(sectionID); if(toReturn.IsNew) { // not found return null; } return toReturn; }
/// <summary> Retrieves the related entity of type 'SectionEntity', 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 'SectionEntity' which is related to this entity.</returns> public virtual SectionEntity GetSingleSection(bool forceFetch) { if( ( !_alreadyFetchedSection || forceFetch || _alwaysFetchSection) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode) { bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.SectionEntityUsingSectionID); SectionEntity newEntity = new SectionEntity(); bool fetchResult = false; if(performLazyLoading) { AddToTransactionIfNecessary(newEntity); fetchResult = newEntity.FetchUsingPK(this.SectionID); } if(fetchResult) { newEntity = (SectionEntity)GetFromActiveContext(newEntity); } else { if(!_sectionReturnsNewIfNotFound) { RemoveFromTransactionIfNecessary(newEntity); newEntity = null; } } this.Section = newEntity; _alreadyFetchedSection = fetchResult; } return _section; }
/// <summary> setups the sync logic for member _section</summary> /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param> private void SetupSyncSection(IEntityCore relatedEntity) { if(_section!=relatedEntity) { DesetupSyncSection(true, true); _section = (SectionEntity)relatedEntity; this.PerformSetupSyncRelatedEntity( _section, new PropertyChangedEventHandler( OnSectionPropertyChanged ), "Section", SD.HnD.DAL.RelationClasses.StaticForumRelations.SectionEntityUsingSectionIDStatic, true, ref _alreadyFetchedSection, new string[] { } ); } }
/// <summary> Removes the sync logic for member _section</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 DesetupSyncSection(bool signalRelatedEntity, bool resetFKFields) { this.PerformDesetupSyncRelatedEntity( _section, new PropertyChangedEventHandler( OnSectionPropertyChanged ), "Section", SD.HnD.DAL.RelationClasses.StaticForumRelations.SectionEntityUsingSectionIDStatic, true, signalRelatedEntity, "Forums", resetFKFields, new int[] { (int)ForumFieldIndex.SectionID } ); _section = null; }
/// <summary>Private CTor for deserialization</summary> /// <param name="info"></param> /// <param name="context"></param> protected ForumEntityBase(SerializationInfo info, StreamingContext context) : base(info, context) { _forumRoleForumActionRights = (SD.HnD.DAL.CollectionClasses.ForumRoleForumActionRightCollection)info.GetValue("_forumRoleForumActionRights", typeof(SD.HnD.DAL.CollectionClasses.ForumRoleForumActionRightCollection)); _alwaysFetchForumRoleForumActionRights = info.GetBoolean("_alwaysFetchForumRoleForumActionRights"); _alreadyFetchedForumRoleForumActionRights = info.GetBoolean("_alreadyFetchedForumRoleForumActionRights"); _threads = (SD.HnD.DAL.CollectionClasses.ThreadCollection)info.GetValue("_threads", typeof(SD.HnD.DAL.CollectionClasses.ThreadCollection)); _alwaysFetchThreads = info.GetBoolean("_alwaysFetchThreads"); _alreadyFetchedThreads = info.GetBoolean("_alreadyFetchedThreads"); _usersWhoStartedThreads = (SD.HnD.DAL.CollectionClasses.UserCollection)info.GetValue("_usersWhoStartedThreads", typeof(SD.HnD.DAL.CollectionClasses.UserCollection)); _alwaysFetchUsersWhoStartedThreads = info.GetBoolean("_alwaysFetchUsersWhoStartedThreads"); _alreadyFetchedUsersWhoStartedThreads = info.GetBoolean("_alreadyFetchedUsersWhoStartedThreads"); _section = (SectionEntity)info.GetValue("_section", typeof(SectionEntity)); if(_section!=null) { _section.AfterSave+=new EventHandler(OnEntityAfterSave); } _sectionReturnsNewIfNotFound = info.GetBoolean("_sectionReturnsNewIfNotFound"); _alwaysFetchSection = info.GetBoolean("_alwaysFetchSection"); _alreadyFetchedSection = info.GetBoolean("_alreadyFetchedSection"); _defaultSupportQueue = (SupportQueueEntity)info.GetValue("_defaultSupportQueue", typeof(SupportQueueEntity)); if(_defaultSupportQueue!=null) { _defaultSupportQueue.AfterSave+=new EventHandler(OnEntityAfterSave); } _defaultSupportQueueReturnsNewIfNotFound = info.GetBoolean("_defaultSupportQueueReturnsNewIfNotFound"); _alwaysFetchDefaultSupportQueue = info.GetBoolean("_alwaysFetchDefaultSupportQueue"); _alreadyFetchedDefaultSupportQueue = info.GetBoolean("_alreadyFetchedDefaultSupportQueue"); this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance()); // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor // __LLBLGENPRO_USER_CODE_REGION_END }