public ActionResult EditMenu(MenuModel menuModel)
 {
     if (!User.Identity.IsAuthenticated)
         return RedirectToAction("LogOn", "Account");
     if (ModelState.IsValid)
     {
         string domain = Utilities.GetMyDomain(Request.Url);
         var scope = ObjectScopeProvider1.GetNewObjectScope();
         var users = (from c in scope.GetOqlQuery<UserAuthentication>().ExecuteEnumerable()
                      where c.Username.ToLower().Equals(User.Identity.Name.ToLower()) && c.Domain.ToLower().Equals(domain.ToLower())
                      select c).ToList();
         if (users.Count == 0)
         {
             ViewData["Status"] = "You are not authorized for this domain [" + domain + "] control panel.";
             return View("Status");
         }
         var menus = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                      where c.Id != null && c.Id.Equals(menuModel.Id) && c.DomainName != null && c.DomainName.ToLower().Equals(domain.ToLower())
                      select c).ToList();
         if (menus.Count > 0)
         {
             var contentPages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable()
                                 where c.Id.Equals(Request.Form["CmbPages"]) && c.DomainName != null && c.DomainName.ToLower().Equals(domain.ToLower())
                                 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) && c.DomainName != null && c.DomainName.ToLower().Equals(domain.ToLower())
                                    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;
                     menu.DomainName = domain;
                     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))
     {
         string domain = Utilities.GetMyDomain(Request.Url);
         var scope = ObjectScopeProvider1.GetNewObjectScope();
         var users = (from c in scope.GetOqlQuery<UserAuthentication>().ExecuteEnumerable()
                      where c.Username.ToLower().Equals(User.Identity.Name.ToLower()) && c.Domain.ToLower().Equals(domain.ToLower())
                      select c).ToList();
         if (users.Count == 0)
         {
             ViewData["Status"] = "You are not authorized for this domain [" + domain + "] control panel.";
             return View("Status");
         }
         var contentPages = (from c in scope.GetOqlQuery<ContentPage>().ExecuteEnumerable()
                             where c.DomainName != null && c.DomainName.ToLower().Equals(domain.ToLower())
                             select c).ToList();
         ViewData["ContentPages"] = contentPages;
         ViewData["menus"] = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                              where c.Id != null && !c.Id.Equals(mid) && c.DomainName != null && c.DomainName.ToLower().Equals(domain.ToLower())
                              select c).ToList();
         ViewData["Pagename"] = string.Empty;
         var menus = (from c in scope.GetOqlQuery<Menu>().ExecuteEnumerable()
                      where c.Id != null && c.Id.Equals(mid) && c.DomainName != null && c.DomainName.ToLower().Equals(domain.ToLower())
                      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");
 }