public async Task <MSSResult> Add(RoleStrActions roleStrActions) { MSSResult mRet = new MSSResult(); try { DateTime dt = DateTime.Now; roleStrActions.UpdatedTime = dt; roleStrActions.CreatedTime = dt; roleStrActions.CreatedBy = userID; roleStrActions.UpdatedBy = userID; bool isRepeat = await _RoleRepo.IsNameRepeat(roleStrActions.role_name); if (isRepeat) { mRet.code = (int)ErrType.Repeat; mRet.msg = "角色名称重复"; } else { mRet.data = await _RoleRepo.Add(roleStrActions); await SaveRedis(); mRet.code = (int)ErrType.OK; } return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> Delete(string ids) { MSSResult mRet = new MSSResult(); try { var action = await _ActionRepo.GetByActionGroup(ids.Split(',')); if (action.Count() > 0) { mRet.code = (int)ErrType.Associated; mRet.msg = "权限组下挂有权限,不允许删除"; return(mRet); } mRet.data = await _ActionGroupRepo.Delete(ids.Split(',')); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public string GetMenu() { //int userID = (int)HttpContext.Session.GetInt32("UserID"); //int userID = 1; //var resp = _UserService.GetByID(userID); //User u = (User)resp.Result.data; //MSSResult<MenuTree> ret = new MSSResult<MenuTree>(); //if (u.is_super) //{ // ret = _UserService.GetMenu().Result; //} //else //{ // ret = _UserService.GetMenu(userID).Result; //} MSSResult <MenuTree> ret = _service.GetMenu().Result; StringBuilder strJson = new StringBuilder(); strJson.Append("{"); int i = 0; foreach (var item in ret.data) { i++; //strJson.Append("\"" + item.path + "\": " + JsonConvert.SerializeObject(item)); strJson.Append("\"" + item.order + "\": " + JsonConvert.SerializeObject(item)); if (i < ret.data.Count()) { strJson.Append(","); } } strJson.Append("}"); return(strJson.ToString()); }
public async Task <MSSResult <MenuTree> > GetMenu() { User u = await _repo.GetByID(userID); MSSResult <MenuTree> mRet = new MSSResult <MenuTree>(); try { List <ActionAll> laa = new List <ActionAll>(); //允许勾选和不对外开放的且为菜单的url if (u.IsSuper) { laa = await _ActionRepo.GetActionAll(); mRet.data = ActionHelper.GetMenuTree(laa.Where( a => (a.Level == (int)ACTION_LEVEL.AllowSelection || a.Level == (int)ACTION_LEVEL.NotAllowAll) && a.GroupID > 0).ToList()); } //根据用户ID获取对应菜单权限 else { laa = await _ActionRepo.GetActionByUser(userID); mRet.data = ActionHelper.GetMenuTree(laa.Where(a => a.GroupID > 0).ToList()); } mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult <ActionGroupView> > GetPageByParm(ActionGroupQueryParm parm) { return(await WithConnection(async c => { MSSResult <ActionGroupView> mRet = new MSSResult <ActionGroupView>(); StringBuilder sql = new StringBuilder(); sql.Append("SELECT a.*,u1.user_name as created_name,u2.user_name as updated_name,d.name as group_type_name ") .Append(" FROM Action_Group a ") .Append(" left join user u1 on a.created_by=u1.id left join user u2 on a.updated_by=u2.id ") .Append(" left join dictionary_tree d on a.group_type=d.id ") .Append(" WHERE 1=1 "); StringBuilder whereSql = new StringBuilder(); if (parm.searchType != null) { whereSql.Append(" and a.group_type=" + parm.searchType); } if (!string.IsNullOrWhiteSpace(parm.searchName)) { whereSql.Append(" and a.group_name like '%" + parm.searchName + "%' "); } sql.Append(whereSql) .Append(" order by a." + parm.sort + " " + parm.order) .Append(" limit " + (parm.page - 1) * parm.rows + "," + parm.rows); var tmp = await c.QueryAsync <ActionGroupView>(sql.ToString()); if (tmp != null) { mRet.data = tmp.ToList(); } mRet.relatedData = await c.QueryFirstOrDefaultAsync <int>( "SELECT count(*) FROM Action_Group a where 1=1 " + whereSql.ToString()); return mRet; })); }
/// <summary> /// 非超级用户可配置的所有权限 /// </summary> /// <returns></returns> public async Task <MSSResult <ActionTree> > GetActionTree() { MSSResult <ActionTree> mRet = new MSSResult <ActionTree>(); try { List <ActionAll> laa = new List <ActionAll>(); //允许勾选 laa = await _ActionRepo.GetActionAll(); //mRet.data = ActionHelper.GetActionTree(laa.Where( // a => a.Level == (int)ACTION_LEVEL.AllowSelection).ToList()); var list = laa.Where( a => a.Level == (int)ACTION_LEVEL.AllowSelection).ToList(); var trees = ActionHelper.ConvertToTree(list); var treenodes = ActionHelper.BuildTreeRecursive(trees, 0); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult <int> > GetByID(int id) { MSSResult <int> mRet = new MSSResult <int>(); try { if (id == 0) { mRet.code = (int)ErrType.ErrParm; mRet.msg = "参数不正确,id不可为0"; return(mRet); } mRet.relatedData = await _RoleRepo.GetByID(id); //List<ActionAll> laa = await _ActionRepo.GetActionAll(); //List<int> actions = await _ActionRepo.GetActionIDByRoleID(id); //mRet.data = ActionHelper.GetCheckedActionTree(laa, actions); mRet.data = (await _ActionRepo.GetActionIDByRoleID(id)).ToList(); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult <RoleView> > GetPageByParm(RoleQueryParm parm) { MSSResult <RoleView> mRet = new MSSResult <RoleView>(); try { parm.page = parm.page == 0 ? 1 : parm.page; parm.rows = parm.rows == 0 ? Common.Const.PAGESIZE : parm.rows; parm.sort = string.IsNullOrWhiteSpace(parm.sort) ? "id" : parm.sort; parm.order = parm.order.ToLower() == "desc" ? "desc" : "asc"; mRet = await _RoleRepo.GetPageByParm(parm); int[] arrRoleID = mRet.data.Select(a => a.Id).ToArray(); List <RoleActions> lra = await _ActionRepo.GetActionByRoles(arrRoleID); foreach (var item in mRet.data) { List <ActionAll> actionAll = lra.Where(a => a.roleID == item.Id).ToList <ActionAll>(); //item.action_trees = ActionHelper.GetActionTree(actionAll); List <ActionTree> actiontree = ActionHelper.ConvertToTree(actionAll); item.action_trees = ActionHelper.BuildTreeRecursive(actiontree, 0); } mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> Delete(string ids) { MSSResult mRet = new MSSResult(); try { string[] arrIds = ids.Split(','); int hasUser = await _UserRepo.GetUserCountByRole(arrIds); if (hasUser > 0) { mRet.code = (int)ErrType.Associated; mRet.msg = "此角色下有用户,不可删除"; } else { mRet.data = await _RoleRepo.Delete(arrIds); await SaveRedis(); mRet.code = (int)ErrType.OK; } return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> GetMenu() { MSSResult mRet = new MSSResult(); try { mRet.data = await _ActionRepo.GetMenu(); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> Delete(string ids) { MSSResult mRet = new MSSResult(); try { mRet.data = await _ActionRepo.Delete(ids.Split(',')); await SaveRedis(); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> Update(RoleStrActions roleStrActions) { MSSResult mRet = new MSSResult(); try { roleStrActions.UpdatedTime = DateTime.Now; roleStrActions.UpdatedBy = userID; var role = await _RoleRepo.GetByID(roleStrActions.Id); if (role == null) { mRet.code = (int)ErrType.NoRecord; mRet.msg = "此角色已不存在"; } else { if (role.role_name != roleStrActions.role_name) { bool isRepeat = await _RoleRepo.IsNameRepeat(roleStrActions.role_name); if (isRepeat) { mRet.code = (int)ErrType.Repeat; mRet.msg = "角色名称重复"; return(mRet); } } mRet.data = await _RoleRepo.Update(roleStrActions); await SaveRedis(); mRet.code = (int)ErrType.OK; } return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> Update(ActionGroup actionGroup) { MSSResult mRet = new MSSResult(); try { actionGroup.UpdatedTime = DateTime.Now; actionGroup.UpdatedBy = userID; mRet.data = await _ActionGroupRepo.Update(actionGroup); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult <RoleView> > GetPageByParm(RoleQueryParm parm) { return(await WithConnection(async c => { MSSResult <RoleView> mRet = new MSSResult <RoleView>(); StringBuilder sql = new StringBuilder(); sql.Append("SELECT DISTINCT a.*,u1.user_name as created_name,u2.user_name as updated_name ") .Append(" FROM Role a ") .Append(" left join user u1 on a.created_by=u1.id left join user u2 on a.updated_by=u2.id ") .Append(" left join role_action ra on a.id=ra.role_id ") .Append(" left join action_info act on act.id=ra.action_id ") .Append(" WHERE 1=1 "); StringBuilder whereSql = new StringBuilder(); if (!string.IsNullOrWhiteSpace(parm.searchName)) { whereSql.Append(" and a.role_name like '%" + parm.searchName + "%' "); } if (parm.searchAction != null) { whereSql.Append(" and act.id=" + parm.searchAction); } if (parm.searchActionGroup != null) { whereSql.Append(" and act.group_id=" + parm.searchActionGroup); } sql.Append(whereSql) .Append(" order by a." + parm.sort + " " + parm.order) .Append(" limit " + (parm.page - 1) * parm.rows + "," + parm.rows); var tmp = await c.QueryAsync <RoleView>(sql.ToString()); if (tmp != null) { mRet.data = tmp.ToList(); } mRet.relatedData = await c.QueryFirstOrDefaultAsync <int>( "select count(DISTINCT a.id) from role a " + " left join role_action ra on a.id = ra.role_id " + " left join action_info act on act.id=ra.action_id where 1=1 " + whereSql.ToString()); return mRet; })); }
public async Task <MSSResult <ActionView> > GetPageByParm(ActionQueryParm parm) { MSSResult <ActionView> mRet = new MSSResult <ActionView>(); try { parm.page = parm.page == 0 ? 1 : parm.page; parm.rows = parm.rows == 0 ? Common.Const.PAGESIZE : parm.rows; parm.sort = string.IsNullOrWhiteSpace(parm.sort) ? "id" : parm.sort; parm.order = parm.order.ToLower() == "desc" ? "desc" : "asc"; mRet = await _ActionRepo.GetPageByParm(parm); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult <ActionView> > GetPageByParm(ActionQueryParm parm) { return(await WithConnection(async c => { MSSResult <ActionView> mRet = new MSSResult <ActionView>(); StringBuilder sql = new StringBuilder(); sql.Append("SELECT a.*,u1.user_name as created_name,u2.user_name as updated_name,ag.group_name, ") .Append(" ai.action_name as parent_name FROM Action_Info a ") .Append(" left join user u1 on a.created_by=u1.id left join user u2 on a.updated_by=u2.id ") .Append(" left join Action_Group ag on ag.id=a.group_id ") .Append(" left join Action_Info ai on ai.id=a.parent_menu ") .Append(" where 1=1 "); StringBuilder whereSql = new StringBuilder(); if (!string.IsNullOrWhiteSpace(parm.searchName)) { whereSql.Append(" and a.action_name like '%" + parm.searchName + "%' "); } if (parm.searchParent != null) { whereSql.Append(" and a.parent_menu=" + parm.searchParent); } if (parm.searchGroup != null) { whereSql.Append(" and a.group_id=" + parm.searchGroup); } sql.Append(whereSql) .Append(" order by a." + parm.sort + " " + parm.order) .Append(" limit " + (parm.page - 1) * parm.rows + "," + parm.rows); var tmp = await c.QueryAsync <ActionView>(sql.ToString()); if (tmp != null) { mRet.data = tmp.ToList(); } mRet.relatedData = await c.QueryFirstOrDefaultAsync <int>( "select count(*) from Action_Info a where 1=1 " + whereSql.ToString()); return mRet; })); }
public async Task <MSSResult> Add(ActionInfo action) { MSSResult mRet = new MSSResult(); try { DateTime dt = DateTime.Now; action.UpdatedTime = dt; action.CreatedTime = dt; action.UpdatedBy = userID; action.CreatedBy = userID; mRet.data = await _ActionRepo.Add(action); await SaveRedis(); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }
public async Task <MSSResult> GetByID(int id) { MSSResult mRet = new MSSResult(); try { if (id == 0) { mRet.code = (int)ErrType.ErrParm; mRet.msg = "参数不正确,id不可为0"; return(mRet); } mRet.data = await _ActionRepo.GetByID(id); mRet.code = (int)ErrType.OK; return(mRet); } catch (Exception ex) { mRet.code = (int)ErrType.SystemErr; mRet.msg = ex.Message; return(mRet); } }