source: iknow-api/Repository/Implementations/UserRepository.cs@ 277bd72

Last change on this file since 277bd72 was 277bd72, checked in by stefansaveski <stefansaveski19@…>, 11 months ago

Refactor all namespaces to iknow_api

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