source: iknow-api/Repository/Implementations/UserRepository.cs@ 8e32210

Last change on this file since 8e32210 was 271178d, checked in by stefansaveski <stefansaveski19@…>, 11 months ago

Refactor all namespaces to iknow_api

  • Property mode set to 100644
File size: 1023 bytes
RevLine 
[9694de9]1using iknow_api.Core.Models;
2using iknow_api.Core.Data;
[fc7b4b4]3using iknow_api.Core.Data;
4using iknow_api.Core.Models;
5using Microsoft.EntityFrameworkCore;
[9694de9]6
[271178d]7namespace iknow_api.Repositories
[9694de9]8{
9 public class UserRepository : IUserRepository
10 {
11 private readonly AppDbContext _context;
12
13 public UserRepository(AppDbContext context)
14 {
15 _context = context;
16 }
17
[fc7b4b4]18 public async Task<bool> UserExistsAsync(string username)
19 {
20 return await _context.User.AnyAsync(u => u.Email == username);
21 }
[9694de9]22
[fc7b4b4]23 public async Task<User?> GetUserByUsernameAsync(string username)
[9694de9]24 {
[fc7b4b4]25 return await _context.User.FirstOrDefaultAsync(u => u.Email == username);
[9694de9]26 }
27
[fc7b4b4]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 }
[9694de9]38 }
39}
Note: See TracBrowser for help on using the repository browser.