public ActionResult Menu_Mapping(int id, ETMenuAccess objmenumap)
 {
     TempData["messagealert"] = string.Empty;
     dbEntities.ETMenuAccesses.Where(n => n.RoleID == id).ToList().ForEach(o => dbEntities.ETMenuAccesses.Remove(o));
     dbEntities.SaveChanges();
     foreach (var item in objmenumap.lstrolemenumap)
     {
         if (item.Status == true)
         {
             ETMenuAccess objmenu = new ETMenuAccess();
             objmenu.MenuID       = item.MenuID;
             objmenu.SubMenuID    = item.SubMenuID;
             objmenu.RoleID       = id;
             objmenu.Status       = item.Status;
             objmenu.CreatedBy    = Convert.ToInt64(Session["UserID"]);
             objmenu.CreatedDate  = Convert.ToDateTime(DateTime.Now.ToString());
             objmenu.ModifiedBy   = Convert.ToInt64(Session["UserID"]);
             objmenu.ModifiedDate = Convert.ToDateTime(DateTime.Now.ToString());
             dbEntities.ETMenuAccesses.Add(objmenu);
             dbEntities.SaveChanges();
         }
     }
     TempData["messagealert"] = Status.Update;
     return(RedirectToAction("/Index"));
 }
        public ActionResult Menu_Mapping(int id)
        {
            List <ETMenu> LstMenu = new List <ETMenu>();

            LstMenu = dbEntities.ETMenus.Where(n => n.Status == true).OrderBy(n => n.OrderNo).ToList();

            List <ETSubMenu> LstSubMenu = new List <ETSubMenu>();

            LstSubMenu = dbEntities.ETSubMenus.Where(n => n.Status == true).OrderBy(n => n.OrderNo).ToList();

            List <ETMenuAccess> LstRolemenumap = new List <ETMenuAccess>();
            ETMenuAccess        objmenumapping = new ETMenuAccess();

            objmenumapping.lstrolemenumap = new List <ETMenuAccess>();
            foreach (var item in LstSubMenu)
            {
                LstRolemenumap = dbEntities.ETMenuAccesses.Where(n => n.SubMenuID == item.SubMenuID && n.RoleID == id).ToList();
                foreach (var roleitem in LstRolemenumap)
                {
                    ETMenuAccess objmenumappingnew = new ETMenuAccess();

                    objmenumappingnew.MenuID    = roleitem.MenuID;
                    objmenumappingnew.SubMenuID = roleitem.SubMenuID;
                    objmenumappingnew.RoleID    = id;
                    objmenumappingnew.Status    = roleitem.Status;
                    objmenumapping.lstrolemenumap.Add(objmenumappingnew);
                }
            }

            objmenumapping.lstsubmenu = LstSubMenu;
            objmenumapping.lstmenu    = LstMenu;
            return(View(objmenumapping));
        }