public async Task <int> Delete(int id) { using (var context = new ThorvaldIdentityDBContext(_serviceProvider.GetRequiredService <DbContextOptions <ThorvaldIdentityDBContext> >())) { DTOrole role = new DTOrole() { Id = id }; context.UserRole.RemoveRange(context.UserRole.Where(i => i.RoleId == id)); context.Role.Remove(dtoConverter.ConvertDTORole(role)); return(await context.SaveChangesAsync()); } }
public async Task <UserValidation> GetUserValidationByUsername(string username) { using (var context = new ThorvaldIdentityDBContext(_serviceProvider.GetRequiredService <DbContextOptions <ThorvaldIdentityDBContext> >())) { UserValidation userValidation = new UserValidation(); var user = await context.User.SingleOrDefaultAsync(u => u.Username == username); userValidation.Id = user.Id; userValidation.Username = user.Username; userValidation.Password = user.Password; return(userValidation); } }
public async Task <List <DTOuser> > GetAll() { using (var context = new ThorvaldIdentityDBContext(_serviceProvider.GetRequiredService <DbContextOptions <ThorvaldIdentityDBContext> >())) { List <DTOuser> dtoUsers = new List <DTOuser>(); var users = await context.User.Include(u => u.UserRole).ThenInclude(r => r.Role).ToListAsync(); foreach (var user in users) { dtoUsers.Add(dtoConverter.ConvertUser(user)); } return(dtoUsers); } }
public async Task <List <DTOrole> > GetAll() { using (var context = new ThorvaldIdentityDBContext(_serviceProvider.GetRequiredService <DbContextOptions <ThorvaldIdentityDBContext> >())) { List <DTOrole> dtoRoles = new List <DTOrole>(); var roles = await context.Role.ToListAsync(); foreach (var role in roles) { dtoRoles.Add(dtoConverter.ConvertRole(role)); } return(dtoRoles); } }