/// <summary> /// 保存用户组权限 /// </summary> /// <param name="roleId"></param> /// <param name="menuIdList"></param> public async Task SaveMenusByRoles(int roleId, List <int> menuIdList) { List <string> sqls = new List <string>(); //加入父级id //string sql = string.Format("select * from Menus where id in({0})", string.Join(",", menuIdList)); //var result = FindListBySql<Menus>(sql); //string parentIds = string.Empty; //if(result != null && result.Count > 0) //{ // menuIdList.AddRange(result.Where(u => u.ParentId != null).Select(u => (int)u.ParentId).ToList()); //} //删除原来的关系 sqls.Add("delete from RoleMenu where rolesid=" + roleId); //添加新关系 menuIdList.Distinct().ToList().ForEach(menuId => { RoleMenu roleMenu = new RoleMenu() { MenusId = menuId, RolesId = roleId }; sqls.Add(EntityToSql.AddSql(roleMenu)); }); await TransQuery(sqls); }
public async Task <int> Update(TEntity entity, params string[] fileds) { var sql = EntityToSql.UpdateSql(entity, fileds); var result = await dbHelper.ExecuteSql(sql); return(result); }
public async Task <int> Delete(TEntity entity) { var sql = EntityToSql.DeleteTemplate(entity); var result = await dbHelper.ExecuteSql(sql); return(result); }
public async Task <int> Insert <T>(T entity) where T : class, new() { string sql = EntityToSql.AddSql <T>(entity); var result = await dbHelper.ExecuteSql(sql); return(result); }
public async Task <int> Insert(TEntity entity) { string sql = EntityToSql.AddSql(entity); var result = Convert.ToInt32(await dbHelper.GetSingle(sql)); return(result); }
public async Task <T> Find <T>(string where) { var sql = EntityToSql.SelectSql <TEntity>(where); var dataSet = await dbHelper.Query(sql); var dataTable = dataSet.Tables[0]; var model = DataTableToEntityHelper.ToEntity <T>(dataTable); return(model); }
/// <summary> /// 删除角色 /// </summary> public async Task TransDelete(int roleId) { List <string> sqls = new List <string>(); sqls.Add(EntityToSql.Delete("roles", "Id", roleId.ToString())); sqls.Add(string.Format("delete from userrole where rolesid={0}", roleId)); sqls.Add(string.Format("delete from rolemenu where rolesid={0}", roleId)); await rolesRepository.TransQuery(sqls); }
public async Task <int> Delete(List <TEntity> entities) { List <string> sqls = new List <string>(); foreach (var entity in entities) { sqls.Add(EntityToSql.DeleteTemplate(entity)); } var result = await dbHelper.ExecuteSqlTran(sqls); return(result); }
/// <summary> /// 角色绑定用户 /// </summary> public async Task UnBindUser(int roleId, string userIds) { var relations = await userRoleRepository.FindList(string.Format("RolesId='{0}' and UserInfoId in({1})", roleId, userIds)); List <string> sqls = new List <string>(); relations.ForEach(relation => { sqls.Add(EntityToSql.DeleteTemplate(relation)); }); await TransQuery(sqls); }
public async Task <int> Insert(List <TEntity> entitys) { var sqls = new List <string>(); foreach (var entity in entitys) { string sql = EntityToSql.AddSql(entity); sqls.Add(sql); } await dbHelper.ExecuteSqlTran(sqls); return(sqls.Count); }
public async Task <int> GetCount(string str) { string sql = ""; if (str.Contains("select")) { sql = str; } else { sql = EntityToSql.SelectSql <TEntity>(str); } return(Convert.ToInt32(await dbHelper.GetSingle(sql))); }
/// <summary> /// 角色绑定用户 /// </summary> public async Task BindUser(int roleId, List <int> userIdList) { List <string> sqls = new List <string>(); userIdList.ForEach(userId => { UserRole userRole = new UserRole() { RolesId = roleId, UserInfoId = userId }; sqls.Add(EntityToSql.AddSql(userRole)); }); await TransQuery(sqls); }