Database Design for Magazine Website with Flexible Horizontal Menus

I need to create a CMS-based website using the asp.net (C #) web form and MS SQL Server as the database for the magazine website in which weekly releases will be issued.

Data examples

MagazinePages Table PageID PageName LangID PagePositionNo PageURL PageInheritance //PageID 1 Home 1 10 Default.aspx 0 2 About Us 1 20 Page.aspx 0 3 PageOne 1 10 Page.aspx 2 4 PageTwo 1 20 Page.aspx 2 5 Media 1 30 Page.aspx 0 6 Video 1 10 Videos.aspx 5 8 News 1 40 News.aspx 0 9 Archive 1 50 # 0 10 Publication 1 60 Page.aspx 0 11 SpanishHome 2 10 Default.aspx 0 12 SpanisAboutUs 2 20 Page.aspx 0 ------------------------------------------------------------------------------ Magazine MagazineID MagazineIssueCode LangID MagazineTitle MagazineLiveIssue(CurrentIssue) 1 1 1 Mag Title 0 2 2 1 Mag Title 1 3 1 2 SpanisgMag Title 0 4 2 2 Mag Title 1 ------------------------------------------------------------------------------ News Table NewsID NewsTitle NewsCatID MagazineID Language 1 News one 100 1 1 2 News two 100 1 1 3 news three 200 1 1 4 News four 300 1 1 5 News Five 100 2 1 6 News Six 300 2 1 7 News seven 200 2 2 ------------------------------------------------------------------------------ 

The problem with the above approach is that I can only create submenus if all entries are in MagazinePages based on the above example. I can create a submenu for "About Us" and Multimedia, how can I create my own so that I can retrieve data from another table, such as news by category (Politics, culture ...) and a problem from the Journal Table (issue 101, issue 102 Issue 103 ....)

I plan to use the ASP Menu control for this, which may not be very flexible, since I will have more than 100 issues of the journal, how or in which menu of several columns I can use with asp.net

My database can have many threads, I would appreciate help in this regard so that I can use this database for this CMS system. Please feel free to ask a question if they relate to this.

Added : If I need to display the entire menu name from the MagazinePages table, then this is easy, but I was asked to create a menu structure, as shown in the example. The problem is that I can generate menus for AboutUs and Multimedia from the MagazinePages Table, but I do not have pages such as "Politics", "Economics", "..." 101, 102, 103 .. information is stored in this table in another table, for example News Category in the news table and problems in the Magazine table. I would prefer to change my table design and make it flexible for reading menu information from a separate table, but I'm not sure how

The news table does not appear in this diagram.

What I did was that I created a ps_Pages table for the CMS pages, for example, Home, Aboutus, Contact, MediaCentre .....

I store pages related to the magazine (this is actually an article with different categories or tags, such as culture, politics, sports, people ...) in the art_Article table

+8
c # sql-server database-design aspmenu-control
source share
4 answers

Why don't you have one page with content?

Just call Page.aspx?Issue=4&Page=4

Then in your code you know that this is the 4th release, and they want Page 4, then you can have the code in the page.aspx file (.vb or .cs) that translates it and then decides on the layout.

For example,

 Page.aspx?Issue=4&Style=Article&Content=5 

So, in the code you could go, Okay, that problem 4 get the database entries for problem 4, they want Content ID 5 from Issue 4, and then inserted the style of the article.

This means that you do not need to add additional pages to the database type, you can simply add content as you wish, and the element that generates URLs to access the content should just show all the content.

+4
source share

I think you need to re-evaluate the database schema. For example, I will have a table called "ParentMenuItems"

This table will include all the elements of the top menu ("Home", "About Us", "Problems", etc.) and have text for the child menu. Then you need to have a ChildMenu table that is related to your parent menu items.

 ParentMenuItems: ============================================================== ID | LinkText | LangID | Other Properties ============================================================== 1 | Home.aspx | 1 | blah blah blah 2 | AboutUs.aspx | 2 | blah blah blah 

Then you may have another table called "ChildMenuItems":

 ChildMenuItems: =============================================================== ID | LinkText | LangID | ParentID | Other Properties... =============================================================== 1 | PageOne.aspx | 1 | 2 | blah blah blah 2 | PageTwo.aspx | 2 | 2 | blah blah blah 

The code may work as follows:

 SELECT * FROM ParentMenuItems - //SQL to get Items 

Then write some foreach code to list the SQL results

 foreach(var ParentMenuItem in ParentMenuItems) { //Get ParentMenuItem ID, run SQL select on child menu items, Example: //SELECT * from ChildMenuItems where ParentID = ID.FROM.PARENT.RESULT // Now you have all the child menu items, foreach those and add to repeater control } 

Hope this helps. Let me know if you have any questions.

TIP: Entity Framework will do this very well.

+3
source share

Create table for menu

 CREATE TABLE [dbo].[tblMenuMaster]( [MenuID] [int] IDENTITY(1,1) NOT NULL, [MenuName] [varchar](100) NULL, [DisplayOrder] [int] NULL, PRIMARY KEY CLUSTERED ( [MenuID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO 

Create another table for the submenu

 CREATE TABLE [dbo].[tblSubMenuMaster]( [SubMenuID] [int] IDENTITY(1,1) NOT NULL, [MenuID] [int] NULL, [SubMenuName] [varchar](100) NULL, [MainMenuDisplayOrder] [int] NULL, [DisplayOrder] [int] NULL, [SubMenuUrl] [varchar](500) NULL, [VisibleInMenu] [bit] NULL, PRIMARY KEY CLUSTERED ( [SubMenuID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO 

Now go to the main page. HTML code:

  <div class="menubar"> <%--<ul class="tabs">--%> <asp:Literal ID="ltMenus" runat="server"></asp:Literal> <%--</ul>--%> </div> 

Code by code:

 private void GenerateMenus() { clsMenu obj = new clsMenu(); System.Data.DataSet ds = new System.Data.DataSet(); String PageName = ""; PageName = Path.GetFileName(Page.AppRelativeVirtualPath); ds = obj.GetMenusByRole(GetRoleId(), PageName); StringBuilder sb = new StringBuilder("<ul class='tabs'>"); foreach (System.Data.DataRow row in ds.Tables[0].Rows) { sb.Append(String.Format("<li class='{0}'><a rel='{1}' href='{1}' > {2} </a> ", Convert.ToString(row["css"]), ResolveUrl(Convert.ToString(row["PagePath"])), Convert.ToString(row["MenuName"]))); //sb.Append(String.Format("<li '><a rel='{0}' href='{0}' > {1} </a> ", ResolveUrl(Convert.ToString(row["PagePath"])), Convert.ToString(row["MenuName"]))); System.Data.DataTable t = CCMMUtility.GetFilterDataforIntColumn("MenuID", Convert.ToString(row["MenuID"]), ds.Tables[1]); if (t.Rows.Count > 0) { sb.Append("<ul>"); for (int i = 0; i < t.Rows.Count; i++) { sb.Append(String.Format("<li><a href='{0}' class='dir' style='cursor: pointer;'>{1}</a></li>", ResolveUrl(Convert.ToString(t.Rows[i]["PagePath"])), Convert.ToString(t.Rows[i]["PageAliasName"]))); } sb.Append("</ul>"); } sb.Append("</li>"); } sb.Append("</ul>"); ltMenus.Text = sb.ToString(); } 

he needs to save the proc to call the dynamic menu according to the Role identifier, as shown below

 CREATE PROCEDURE [dbo].[proc_GetMenusByRole] ( @RoleId int, @PageName varchar(100) ) AS SET NOCOUNT ON; SELECT mm.MenuID, mm.MenuName,dbo.Extract_CssNameForMenuByMenuIDAndPageName(mm.MenuID, @PageName) as css ,dbo.proc_Extract_MenuPageByRoleIDAndMenuID(@RoleId, mm.MenuID) as PagePath , mm.DisplayOrder FROM tblMenuMaster mm WHERE mm.MenuID IN (SELECT s.MenuID from tblSiteRolePermissions p INNER JOIN tblSitePages s ON p.fkSitePageId = s.pkSitePageId WHERE (p.fkRoleId = @RoleId and p.ViewOnly=1)) Union All select 0 as menuid ,'Change Password' as MenuName, case @pagename when 'ChangePassword.aspx' then 'active' else '' end as css,'~/User/ChangePassword.aspx' as PagePath, 10000 as Displayorder ORDER BY DisplayOrder SELECT s.MenuID, s.pkSitePageId, s.PageAliasName, s.SitePageName,s.pagepath from tblSiteRolePermissions p INNER JOIN tblSitePages s ON p.fkSitePageId = s.pkSitePageId WHERE (p.fkRoleId =@RoleId and p.ViewOnly=1) ORDER BY s.pkSitePageId 

// a new sp is launched here

 CREATE function [dbo].[Extract_CssNameForMenuByMenuIDAndPageName](@MenuID int, PageName varchar(100)) returns nvarchar(50) as begin declare @result nvarchar(50) set @result = '' IF EXISTS (SELECT pkSitePageId FROM tblsitepages WHERE (MenuID = @MenuID) AND (UPPER(SitePageName) = @PageName)) BEGIN SET @result = 'active' END return @result end 

// use another sp

 CREATE function [dbo].[proc_Extract_MenuPageByRoleIDAndMenuID] (@RoleId int, @MenuID int) returns nvarchar(500) as begin declare @result nvarchar(500) SELECT top 1 @result = s.pagepath FROM tblSitePages AS s INNER JOIN tblSiteRolePermissions AS p ON s.pkSitePageId = p.fkSitePageId WHERE (p.fkRoleId = @RoleId) AND (s.MenuID = @MenuID) and p.ViewOnly=1 ORDER BY s.pkSitePageId return @result end 

This is just a way to do it, you can change it according to your requirement .........

proc_Extract_MenuPageByRoleIDAndMenuID sp is used to get the name of the page and its path,

Extract_CssNameForMenuByMenuIDAndPageName sp is used to set the class active to the first li means the first menu. Hop this will help you ..... Its a working code.

+2
source share

I'm not sure I understood what you need, but I assume that you want to create a menu for the entire system, not a menu for each magazine, right?

If so, I think you're looking for the wrong problem: the problem is not the database schema, but that your menu should be automatically populated with N different tables that do not have a standard standard.

I would create a menu table - and make the magazine pages and menus two separate tables: if you create a CMS-like system, you will probably have a page where I can edit categories, problems and - why not - the menu entries, with the exception of any other tables.

In addition, I would create a system of "tags", where all my news and problems could be "tagged" rather than placed in an exclusive category. This would allow receiving news that tells about politics and culture at the same time. Then, instead of directing the user to many different .aspx pages, you should use the content.aspx tag? = Politics. When creating a tag, I will have the opportunity to add this tag to the menu table in the "news", "problems" section, etc. The same goes for category and problems.

If this does not meet your needs, you can try these options, but all other solutions, except for a specific table for entries in the menu, cause in my head a "warning, future problems":

1 - create a menu table, a stored procedure that fills this table, following certain rules, and then triggers triggers in tables such as "category" that will truncate and call the stored procedure, rewrite the menu every time the content changes (sounds like fast correct me)

2 - add "submenu_table", "submenu_field", "submenu_condition", etc. to the log pages and use dynamic sql to select data (something like Set @SQL='Select '+ submenu_field + ' from '+ submenu_table + ' where ' + submenu_condition; Exec(@SQL) ) (another quick fix, hard and probably a slow request)

(edit :) 3 - there is also a hierachyId field in sql 2008 and higher ([http://blogs.msdn.com/b/manisblog/archive/2007/08/17/sql-server-2008-hierarchyid.aspx]) one

+2
source share

All Articles