public async Task <ActionResult <IEnumerable <Sys_Dm_GroupRole> > > r1GetListGroupRole(OptionNull options) { try { RequestToken token = CommonData.GetDataFromToken(User); var tables = _context.Sys_Dm_GroupRole.Select(a => new { a.Name, a.Id, a.IsOrder, a.IsAdminCom, a.IsAdminDep, a.IsAdminNest, a.IsActive, a.DepartmentId, a.CompanyId }).AsQueryable(); if (options.companyId == 0) { tables = tables.Where(x => x.CompanyId == 0); } if (options.companyId > 0 && options.departmentId == 0 && options.nestId == 0) { tables = tables.Where(x => x.CompanyId == options.companyId && x.DepartmentId == 0); } if (options.departmentId > 0 && options.nestId == 0) { tables = tables.Where(x => x.DepartmentId == options.departmentId); } if (options.nestId > 0) { tables = tables.Where(x => x.DepartmentId == options.nestId); } var qrs = await tables.OrderBy(x => x.IsOrder).ToListAsync(); return(new ObjectResult(new { error = 0, data = qrs })); } catch (Exception) { return(new ObjectResult(new { error = 1 })); } }
public async Task <ActionResult <IEnumerable <Sys_Dm_GroupRole> > > r1GetListGroupRole(OptionNull options) { try { var userId = Convert.ToInt32(User.Claims.First(c => c.Type == "UserId").Value); var tables = _context.Sys_Dm_GroupRole.Select(a => new { a.Name, a.Id, a.IsOrder, a.IsAdminCom, a.IsAdminDep, a.IsAdminNest, a.IsActive, a.DepartmentId, a.CompanyId }).AsQueryable(); if (options.companyId == 0) { tables = tables.Where(x => x.CompanyId == 0); } if (options.companyId > 0 && options.departmentId == 0 && options.nestId == 0) { tables = tables.Where(x => x.CompanyId == options.companyId && x.DepartmentId == 0); } if (options.departmentId > 0 && options.nestId == 0) { tables = tables.Where(x => x.DepartmentId == options.departmentId); } if (options.nestId > 0) { tables = tables.Where(x => x.DepartmentId == options.nestId); } var qrs = await tables.OrderBy(x => x.IsOrder).ToListAsync(); return(new ObjectResult(new { error = 0, data = qrs })); } catch (Exception) { return(new ObjectResult(new { error = 1 })); } }