示例#1
0
        public object EditRole_MenuFunction(EditRoleMenu model)
        {
            Result rs = new Result();

            try
            {
                var sysRoles = dbContext.AC_SysRoles.FirstOrDefault(k => k.Id == model.Id);
                if (sysRoles == null)
                {
                    rs.Code      = 1001;
                    rs.strResult = "角色Id【" + model.Id + "】不存在,请刷新界面";
                    return(Json(rs));
                }
                //菜单分配
                sysRoles.BA_SysMenu.Clear();
                foreach (var item in model.Menu ?? new List <string>())
                {
                    var sysMenu = dbContext.BA_SysMenu.FirstOrDefault(k => k.Code == item);
                    if (sysMenu == null)
                    {
                        rs.Code      = 1001;
                        rs.strResult = "菜单编码【" + item + "】不存在,请刷新界面";
                        return(Json(rs));
                    }
                    sysRoles.BA_SysMenu.Add(sysMenu);
                }
                //功能分配
                sysRoles.BA_SysCommand.Clear();
                foreach (var item in model.Function ?? new List <string>())
                {
                    var sysCommand = dbContext.BA_SysCommand.FirstOrDefault(k => k.Code == item);
                    if (sysCommand == null)
                    {
                        rs.Code      = 1001;
                        rs.strResult = "功能编码【" + item + "】不存在,请刷新界面";
                        return(Json(rs));
                    }
                    sysRoles.BA_SysCommand.Add(sysCommand);
                }

                dbContext.SaveChanges();
                rs.Code      = 0;
                rs.strResult = "分配成功";
                return(Json(rs));
            }
            catch (Exception ex)
            {
                rs.Code      = 0;
                rs.strResult = ex.Message;
                return(Json(rs));
            }
        }
示例#2
0
 public IHttpActionResult EditRole_MenuFunction(EditRoleMenu model)
 {
     try
     {
         var sysRoles = dbContext.AC_SysRoles.FirstOrDefault(k => k.Id == model.Id);
         if (sysRoles == null)
         {
             return(JsonResultHelper.JsonResult(1000, "角色Id【" + model.Id + "】不存在,请刷新界面"));
         }
         //菜单分配
         sysRoles.BA_SysMenu.Clear();
         foreach (var item in model.Menu ?? new List <string>())
         {
             var sysMenu = dbContext.BA_SysMenu.FirstOrDefault(k => k.Code == item);
             if (sysMenu == null)
             {
                 return(JsonResultHelper.JsonResult(1000, "菜单编码【" + item + "】不存在,请刷新界面"));
             }
             sysRoles.BA_SysMenu.Add(sysMenu);
         }
         //功能分配
         sysRoles.BA_SysCommand.Clear();
         foreach (var item in model.Function ?? new List <string>())
         {
             var sysCommand = dbContext.BA_SysCommand.FirstOrDefault(k => k.Code == item);
             if (sysCommand == null)
             {
                 return(JsonResultHelper.JsonResult(1000, "功能编码【" + item + "】不存在,请刷新界面"));
             }
             sysRoles.BA_SysCommand.Add(sysCommand);
         }
         dbContext.SaveChanges();
         return(JsonResultHelper.JsonResult(0, "操作成功"));
     }
     catch (Exception ex)
     {
         return(JsonResultHelper.JsonResult(1000, ex.Message));
     }
 }