예제 #1
0
 public void deleteMenuByRole(int menuID)
 {
     //delete menu by role first
     var mbRoleData = from x in entity.menuByRoles where x.menuId == menuID select x;
     List<menuByRole> mbRoleList = new List<menuByRole>();
     mbRoleList = mbRoleData.ToList();
     for (int i = 0; i < mbRoleList.Count; i++)
     {
         menuByRole mbRole = new menuByRole();
         mbRole = mbRoleList[i];
         entity.menuByRoles.Remove(mbRole);
         entity.SaveChanges();
     }
 }
예제 #2
0
        public void addMenuByRole(int menuid, List<string> roleIdList)
        {
            //delete all menubyrole as menuid
            this.deleteMenuByRole(menuid);
            //update new all
            for (int i = 0; i < roleIdList.Count; i++)
            {
                menuByRole mbRoleData = new menuByRole();
                var mbRoleID = from x in entity.menuByRoles orderby x.menuByRoleId descending select x;
                mbRoleData.menuByRoleId = (mbRoleID.FirstOrDefault().menuByRoleId) + 1;
                mbRoleData.menuId = menuid;
                mbRoleData.roleId = roleIdList[i];

                entity.menuByRoles.Add(mbRoleData);
                entity.SaveChanges();
            }
        }