source: iknow-api/Repository/Implementations/UserRepository.cs@ 7a1fe00

Last change on this file since 7a1fe00 was 1e58098, checked in by imbrsk <boris696boris@…>, 11 months ago

added remaining methods to refreshtoken feature

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[5eb7847]1using iknow_api.Models;
2using iknow_api.Data;
3using iknow_api.Models;
[fc7b4b4]4using Microsoft.EntityFrameworkCore;
[9694de9]5
[271178d]6namespace iknow_api.Repositories
[9694de9]7{
8 public class UserRepository : IUserRepository
9 {
10 private readonly AppDbContext _context;
11
12 public UserRepository(AppDbContext context)
13 {
14 _context = context;
15 }
16
[fc7b4b4]17 public async Task<bool> UserExistsAsync(string username)
18 {
19 return await _context.User.AnyAsync(u => u.Email == username);
20 }
[9694de9]21
[fc7b4b4]22 public async Task<User?> GetUserByUsernameAsync(string username)
[9694de9]23 {
[fc7b4b4]24 return await _context.User.FirstOrDefaultAsync(u => u.Email == username);
[9694de9]25 }
[1e58098]26 public async Task<User?> GetOnlyUserByIdAsync(int id)
27 {
28 return await _context.User.FirstOrDefaultAsync(u => u.Id == id);
29 }
[fc7b4b4]30 public async Task AddUserAsync(User user)
31 {
32 _context.User.Add(user);
33 await _context.SaveChangesAsync();
34 }
35
36 public async Task<int> GetUsersCountAsync()
37 {
38 return await _context.User.CountAsync();
39 }
[9694de9]40 }
41}
Note: See TracBrowser for help on using the repository browser.