source: iknow-api/Repository/Implementations/UserRepository.cs@ 9694de9

Last change on this file since 9694de9 was 9694de9, checked in by imbrsk <boris696boris@…>, 11 months ago

Refactor user management: update models, repositories, and services; remove obsolete files

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[9694de9]1using System.Threading;
2using System.Threading.Tasks;
3using Microsoft.EntityFrameworkCore;
4using iknow_api.Core.Models;
5using iknow_api.Repository.Interfaces;
6using iknow_api.Core.Data;
7
8namespace iknow_api.Repository
9{
10 public class UserRepository : IUserRepository
11 {
12 private readonly AppDbContext _context;
13
14 public UserRepository(AppDbContext context)
15 {
16 _context = context;
17 }
18
19 public Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default)
20 => _context.User.AnyAsync(u => u.Email == email, cancellationToken);
21
22 public async Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default)
23 {
24 await _context.User.AddAsync(user, cancellationToken);
25 await _context.SaveChangesAsync(cancellationToken);
26 return user;
27 }
28
29 public Task<User?> GetUserByIdAsync(int id, CancellationToken cancellationToken = default)
30 => _context.User.FindAsync(new object[] { id }, cancellationToken).AsTask();
31 }
32}
Note: See TracBrowser for help on using the repository browser.