Beispiel #1
0
 public async Task <List <AppRole> > GetRolesByUserName(string userName)
 {
     using var context = new JwtWebApiContext();
     return(await context.AppUsers.Join(context.AppUserRoles, u => u.Id, ur => ur.AppUserId, (user, userRole) => new
     {
         user = user,
         userRole = userRole
     }).Join(context.AppRoles, two => two.userRole.AppRoleId, r => r.Id, (twoTable, role) => new
     {
         user = twoTable.user,
         userRole = twoTable.userRole,
         role = role
     }).Where(I => I.user.UserName == userName).Select(I => new AppRole
     {
         Id = I.role.Id,
         Name = I.role.Name
     }).ToListAsync());
 }
 public async Task Uptade(TEntity entity)
 {
     using var context = new JwtWebApiContext();
     context.Update(entity);
     await context.SaveChangesAsync();
 }
 public async Task Remove(TEntity entity)
 {
     using var context = new JwtWebApiContext();
     context.Remove(entity);
     await context.SaveChangesAsync();
 }
 public async Task <TEntity> GetById(int id)
 {
     using var context = new JwtWebApiContext();
     return(await context.Set <TEntity>().FindAsync(id));
 }
 public async Task <TEntity> GetByFilter(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new JwtWebApiContext();
     return(await context.Set <TEntity>().FirstOrDefaultAsync(filter));
 }
 public async Task <List <TEntity> > GetAllByFilter(Expression <Func <TEntity, bool> > filter)
 {
     using var context = new JwtWebApiContext();
     return(await context.Set <TEntity>().Where(filter).ToListAsync());
 }
 public async Task <List <TEntity> > GetAll()
 {
     using var context = new JwtWebApiContext();
     return(await context.Set <TEntity>().ToListAsync());
 }