|
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
|
| Line | |
|---|
| 1 | using System.Threading;
|
|---|
| 2 | using System.Threading.Tasks;
|
|---|
| 3 | using Microsoft.EntityFrameworkCore;
|
|---|
| 4 | using iknow_api.Core.Models;
|
|---|
| 5 | using iknow_api.Repository.Interfaces;
|
|---|
| 6 | using iknow_api.Core.Data;
|
|---|
| 7 |
|
|---|
| 8 | namespace 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.