public ActionResult AddMenu(MenuModel menuModel)
 {
     if (User.Identity.IsAuthenticated)
     {
         if (ModelState.IsValid)
         {
             var scope = ObjectScopeProvider1.GetNewObjectScope();
             ViewData["ContentPages"] = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable()
                                         select c).ToList();
             List<Menu> menus = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                                 where c.Name.ToLower().Equals(menuModel.MenuName.ToLower().Trim())
                                 select c).ToList();
             if (menus.Count == 0)
             {
                 var contentPages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable()
                                     where c.Id.Equals(Request.Form["CmbPages"])
                                     select c).ToList();
                 if (contentPages.Count > 0)
                 {
                     string selectedMenu = Request.Form["CmbParentMenu"];
                     string parentID = string.Empty;
                     if (!string.IsNullOrEmpty(selectedMenu) && selectedMenu.ToLower().Trim() != "--root--")
                     {
                         var menuIds = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                                     where c.Id != null && c.Id.Equals(selectedMenu)
                                     select c.Id).ToList();
                         if (menuIds.Count > 0)
                             parentID = menuIds[0];
                     }
                     scope.Transaction.Begin();
                     var menu = new Menu
                     {
                         Name = menuModel.MenuName,
                         ParentId = parentID,
                         Page = contentPages[0]
                     };
                     scope.Add(menu);
                     scope.Transaction.Commit();
                     ViewData["menus"] = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                                          select c).ToList();
                     return View("menus");
                     //return RedirectToAction("Menus");
                 }
                 ModelState.AddModelError("", "The Link page is not selected.");
             }
             else
                 ModelState.AddModelError("Menu name", "The given menu is already exists");
         }
         return View(menuModel);
     }
     return RedirectToAction("LogOn", "Account");
 }
 public ActionResult EditMenu(MenuModel menuModel)
 {
     if (!User.Identity.IsAuthenticated)
         return RedirectToAction("LogOn", "Account");
     if (ModelState.IsValid)
     {
         var scope = ObjectScopeProvider1.GetNewObjectScope();
         var menus = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                      where c.Id != null && c.Id.Equals(menuModel.Id)
                      select c).ToList();
         if (menus.Count > 0)
         {
             var contentPages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable()
                                 where c.Id.Equals(Request.Form["CmbPages"])
                                 select c).ToList();
             if (contentPages.Count > 0)
             {
                 string selectedMenu = Request.Form["CmbParentMenu"];
                 string parentID = string.Empty;
                 if (!string.IsNullOrEmpty(selectedMenu) && selectedMenu.ToLower().Trim() != "--root--")
                 {
                     var menuIds = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                                    where c.Id != null && c.Id.Equals(selectedMenu)
                                    select c.Id).ToList();
                     if (menuIds.Count > 0)
                         parentID = menuIds[0];
                 }
                 foreach (Menu menu in menus)
                 {
                     scope.Transaction.Begin();
                     menu.Name = menuModel.MenuName;
                     menu.Page = contentPages[0];
                     menu.ParentId = parentID;
                     scope.Add(menu);
                     scope.Transaction.Commit();
                 }
             }
         }
     }
     return RedirectToAction("Menus");
 }
 public ActionResult EditMenu(string mid)
 {
     if (!User.Identity.IsAuthenticated)
         return RedirectToAction("LogOn", "Account");
     if (!string.IsNullOrEmpty(mid))
     {
         var scope = ObjectScopeProvider1.GetNewObjectScope();
         var contentPages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable()
                             select c).ToList();
         ViewData["ContentPages"] = contentPages;
         ViewData["menus"] = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                              where c.Id != null && !c.Id.Equals(mid)
                              select c).ToList();
         ViewData["Pagename"] = string.Empty;
         var menus = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                      where c.Id != null && c.Id.Equals(mid)
                      select c).ToList();
         if (menus.Count > 0)
         {
             ViewData["ParentMenuId"] = menus[0].ParentId;
             var menuModel = new MenuModel
                                 {
                                     MenuName = menus[0].Name,
                                     Id = menus[0].Id
                                 };
             foreach (ContentPage contentPage in contentPages)
             {
                 if (contentPage.Name.ToLower().Equals(menus[0].Page.Name.ToLower()))
                 {
                     ViewData["Pagename"] = contentPage.Name;
                     break;
                 }
             }
             return View(menuModel);
         }
     }
     return RedirectToAction("Menus");
 }