Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Test Driving NHibernate 3.0, LINQ and the Entity Framework CTP 5 with the Abstract Factory Design Pattern

, 2 Apr 2011
Developing an N-Tier application with C#
CodeProjectORM.zip
ORMApplicationServices
bin
Debug
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
ORMApplicationServices.dll
ORMApplicationServices.pdb
ResolveAssemblyReference.cache
TempPE
Release
ORMApplicationServices.csproj.user
ORMApplicationServices.suo
Properties
ORMDatabase
ORMDatabase.mdf
ORMDatabase_log.ldf
ORMDataModel
bin
Debug
Release
ORMDataModel.dll
ORMDataModel.pdb
Models
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
ORMDataModel.dll
ORMDataModel.pdb
ResolveAssemblyReference.cache
TempPE
Release
DesignTimeResolveAssemblyReferencesInput.cache
ORMDataModel.dll
ORMDataModel.pdb
TempPE
ORMDataModel.csproj.user
ORMDataModel.suo
Properties
ORMDataServices
bin
Debug
Release
DataFactories
EntityFramework
LinqToSQL
NHibernate
DataFactory
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
ORMDataServices.dll
ORMDataServices.pdb
ResolveAssemblyReference.cache
TempPE
Release
ORMDataServices.csproj.user
ORMDataServices.suo
Properties
ORMNhiberateMaps
bin
Debug
ORMNhibernateMaps.dll
ORMNhibernateMaps.pdb
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
ORMNhibernateMaps.dll
ORMNhibernateMaps.pdb
TempPE
Release
ORMNhiberateMaps.suo
ORMNhibernateMaps.csproj.user
Properties
ORMUtilities
bin
Debug
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
ORMUtilities.dll
ORMUtilities.pdb
ResolveAssemblyReference.cache
TempPE
Release
ORMUtilities.csproj.user
ORMUtilities.suo
Properties
ORMWebApplicationMVC
ORMWebApplicationMVC.suo
ORMWebApplicationMVC
App_Data
bin
Antlr3.Runtime.dll
Castle.Core.dll
Iesi.Collections.dll
Iesi.Collections.pdb
NHibernate.ByteCode.Castle.dll
NHibernate.dll
ORMApplicationServices.dll
ORMApplicationServices.pdb
ORMDataModel.dll
ORMDataModel.pdb
ORMDataServices.dll
ORMDataServices.pdb
ORMNhibernateMaps.dll
ORMNhibernateMaps.pdb
ORMUtilities.dll
ORMUtilities.pdb
ORMWebApplicationMVC.dll
ORMWebApplicationMVC.pdb
Remotion.Data.Linq.dll
Content
DownArrow.gif
Images
DownArrow.gif
SampleApplication.jpg
UpArrow.gif
themes
base
images
ui-bg_flat_0_aaaaaa_40x100.png
ui-bg_flat_75_ffffff_40x100.png
ui-bg_glass_55_fbf9ee_1x400.png
ui-bg_glass_65_ffffff_1x400.png
ui-bg_glass_75_dadada_1x400.png
ui-bg_glass_75_e6e6e6_1x400.png
ui-bg_glass_95_fef1ec_1x400.png
ui-bg_highlight-soft_75_cccccc_1x100.png
ui-icons_222222_256x240.png
ui-icons_2e83ff_256x240.png
ui-icons_454545_256x240.png
ui-icons_888888_256x240.png
ui-icons_cd0a0a_256x240.png
UpArrow.gif
Controllers
Global.asax
Helpers
Models
obj
Debug
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
ORMWebApplicationMVC.dll
ORMWebApplicationMVC.pdb
ResolveAssemblyReference.cache
TempPE
ORMWebApplicationMVC.csproj.user
Properties
Scripts
Views
Account
Customer
Home
Orders
Products
Shared
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace ORMWebApplication.Helpers
{

    public class MenuHelper
    {
        public TopLevelMenu topLevelMenuItems;
        public SubLevelMenu subLevelMenuItems;
        public List<TopLevelMenu> topLevelMenu;
        public List<SubLevelMenu> subLevelMenu;


        public MenuHelper()
        {
            ConstructMenu();
        }

        /// <summary>
        /// Build Menu
        /// </summary>
        /// <param name="selectedMenuItem"></param>
        /// <param name="selectedSubMenuItem"></param>
        /// <returns></returns>
        public string BuildMenu(string selectedMenuItem, string selectedSubMenuItem)
        {


            int selectedMenuItemID = 0;
            int selectedSubMenuItemID = 0;
     
            var subMenu = from subMenuItems in subLevelMenu
                          where subMenuItems.menuController == selectedMenuItem
                          && subMenuItems.menuText == selectedSubMenuItem
                          select subMenuItems;

            foreach (var m in subMenu)
            {
                selectedMenuItemID = m.menuID;
                selectedSubMenuItemID = m.subMenuID;

            }

            return BuildMenu(selectedMenuItemID, selectedSubMenuItemID);

        }

        /// <summary>
        /// Consruct
        /// </summary>
        private void ConstructMenu()
        {
            topLevelMenu = new List<TopLevelMenu>();
            subLevelMenu = new List<SubLevelMenu>();

            topLevelMenuItems = new TopLevelMenu();
            topLevelMenuItems.menuID = 1;
            topLevelMenuItems.menuText = "Customers";
            topLevelMenuItems.menuAction = "Index";
            topLevelMenuItems.menuController = "Customer";
            topLevelMenu.Add(topLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 1;
            subLevelMenuItems.subMenuID = 1;
            subLevelMenuItems.menuText = "Customer Entry";
            subLevelMenuItems.menuAction = "Index";
            subLevelMenuItems.menuController = "Customer";
            subLevelMenu.Add(subLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 1;
            subLevelMenuItems.subMenuID = 2;
            subLevelMenuItems.menuText = "Customer Inquiry";
            subLevelMenuItems.menuAction = "CustomerInquiry";
            subLevelMenuItems.menuController = "Customer";
            subLevelMenu.Add(subLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 1;
            subLevelMenuItems.subMenuID = 3;
            subLevelMenuItems.menuText = "Customer Audit";
            subLevelMenuItems.menuAction = "CustomerAudit";
            subLevelMenuItems.menuController = "Customer";
            subLevelMenu.Add(subLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 1;
            subLevelMenuItems.subMenuID = 4;
            subLevelMenuItems.menuText = "Customer Reporting";
            subLevelMenuItems.menuAction = "CustomerReporting";
            subLevelMenuItems.menuController = "Customer";
            subLevelMenu.Add(subLevelMenuItems);

            topLevelMenuItems = new TopLevelMenu();
            topLevelMenuItems.menuID = 2;
            topLevelMenuItems.menuText = "Products";
            topLevelMenuItems.menuAction = "Index";
            topLevelMenuItems.menuController = "Products";
            topLevelMenu.Add(topLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 2;
            subLevelMenuItems.subMenuID = 1;
            subLevelMenuItems.menuText = "Create a product";
            subLevelMenuItems.menuAction = "ProductEntry";
            subLevelMenuItems.menuController = "Products";
            subLevelMenu.Add(subLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 2;
            subLevelMenuItems.subMenuID = 2;
            subLevelMenuItems.menuText = "Product Inquiry";
            subLevelMenuItems.menuAction = "ProductInquiry";
            subLevelMenuItems.menuController = "Products";
            subLevelMenu.Add(subLevelMenuItems);

            topLevelMenuItems = new TopLevelMenu();
            topLevelMenuItems.menuID = 3;
            topLevelMenuItems.menuText = "Orders";
            topLevelMenuItems.menuAction = "Index";
            topLevelMenuItems.menuController = "Orders";
            topLevelMenu.Add(topLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 3;
            subLevelMenuItems.subMenuID = 1;
            subLevelMenuItems.menuText = "Create a order";
            subLevelMenuItems.menuAction = "OrderEntry";
            subLevelMenuItems.menuController = "Orders";
            subLevelMenu.Add(subLevelMenuItems);

            subLevelMenuItems = new SubLevelMenu();
            subLevelMenuItems.menuID = 3;
            subLevelMenuItems.subMenuID = 2;
            subLevelMenuItems.menuText = "Order Inquiry";
            subLevelMenuItems.menuAction = "OrderInquiry";
            subLevelMenuItems.menuController = "Orders";
            subLevelMenu.Add(subLevelMenuItems);

        }

        /// <summary>
        /// Build Menu
        /// </summary>
        /// <param name="selectedMenuItem"></param>
        /// <param name="selectedSubMenuItem"></param>
        /// <returns></returns>
        public string BuildMenu(int selectedMenuItem, int selectedSubMenuItem)
        {          
            string htmlTable = BuildHTMLTable(selectedMenuItem, selectedSubMenuItem);
            return htmlTable;
        }

        /// <summary>
        /// Build HTML Table
        /// </summary>
        /// <param name="selectedMenuItem"></param>
        /// <param name="selectedSubMenuItem"></param>
        /// <returns></returns>
        private string BuildHTMLTable(int selectedMenuItem, int selectedSubMenuItem)
        {
            int counter = 0;

            StringBuilder menuBuilder = new StringBuilder();
            menuBuilder.Append("<table id='MyMainMenuTable1' cellpadding=0 cellspacine=0 border=0; ><tr><td>");
            menuBuilder.Append("<table id='MyMainMenuTable2' cellpadding=0 cellspacing=0><tr>");

            var mainMenu = from topMenu in topLevelMenu select topMenu;
            counter = 0;

            foreach (var m in mainMenu)
            {
                counter++;
                if (selectedMenuItem != m.menuID)
                {
                    menuBuilder.Append("<td style='width:100px; text-align:center; padding: 5px 5px 5px 5px; background-color:White'>");
                    menuBuilder.Append("<a href='/" + m.menuController + "/" + m.menuAction + "'/>");
                    menuBuilder.Append(m.menuText);
                    menuBuilder.Append("</td>");
                }
                else
                {
                    menuBuilder.Append("<td style='width:100px; text-align:center; background-color:#D3DCE5'>");
                    menuBuilder.Append(m.menuText);
                    menuBuilder.Append("</td>");

                }
                if (counter < mainMenu.Count())
                {
                    menuBuilder.Append("<td>&nbsp;</td>");
                }
            }

            menuBuilder.Append("</tr></table>");
            menuBuilder.Append("</td></tr></table>");

            var subMenu = from subMenuItems in subLevelMenu
                          where subMenuItems.menuID == selectedMenuItem
                          select subMenuItems;

            menuBuilder.Append("<table id='menuTable' style='width:100%; border=0; border-color:#D3DCE5;'><tr><td>");
            menuBuilder.Append("<table id='SubMenuTable' cellpadding=0 cellspacing=0><tr>");
            counter = 0;

            foreach (var m in subMenu)
            {
                counter++;
                if (selectedSubMenuItem == m.subMenuID)
                {
                    menuBuilder.Append("<td style='background-color:WhiteSmoke'>");
                    menuBuilder.Append(m.menuText);
                    menuBuilder.Append("</td>");
                }
                else
                {
                    menuBuilder.Append("<td>");
                    menuBuilder.Append("<a href='/" + m.menuController + "/" + m.menuAction + "'/>");
                    menuBuilder.Append(m.menuText);
                    menuBuilder.Append("</a>");
                    menuBuilder.Append("</td>");
                }

                if (counter < subMenu.Count())
                    menuBuilder.Append("<td>|</td>");
            }
            menuBuilder.Append("</tr></table>");
            menuBuilder.Append("</td></tr></table>");

            string htmlTable = menuBuilder.ToString();
            return htmlTable;
        }


    }

    public class TopLevelMenu
    {
        public int menuID { get; set; }
        public string menuText { get; set; }
        public string menuController { get; set; }
        public string menuAction { get; set; }
    }

    public class SubLevelMenu
    {
        public int menuID { get; set; }
        public int subMenuID { get; set; }
        public string menuText { get; set; }
        public string menuController { get; set; }
        public string menuAction { get; set; }

    }


}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mark J. Caplin
Software Developer Caplin Systems
United States United States
Mark Caplin has specialized in Information Technology solutions for 25 years. Specializing in full life-cycle development projects for both enterprise-wide systems and Internet/Intranet based solutions.
 
For the past ten years or so, Mark has specialized in the Microsoft .NET framework using both C# and VB.NET as his tools of choice.
 
When not coding, Mark enjoys playing tennis, listening to U2 music, watching Miami Dolphins football and watching movies in Blu-Ray technology.
 
In between all this, his wife of over 20 years, feeds him well with some great home cooked meals.
 
...

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 2 Apr 2011
Article Copyright 2011 by Mark J. Caplin
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid