Changeset 5b42c8d for iknow-api/Repository
- Timestamp:
- 10/22/25 22:40:03 (11 months ago)
- Branches:
- master
- Children:
- 41e4f9f
- Parents:
- d025ba3
- Location:
- iknow-api/Repository
- Files:
-
- 2 edited
-
Implementations/UserRepository.cs (modified) (2 diffs)
-
Interface/IUserRepository.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
iknow-api/Repository/Implementations/UserRepository.cs
rd025ba3 r5b42c8d 1 using System.Threading; 2 using System.Threading.Tasks; 1 using iknow_api.Core.Models; 2 using iknow_api.Core.Data; 3 using iknow_api.Core.Data; 4 using iknow_api.Core.Models; 3 5 using Microsoft.EntityFrameworkCore; 4 using iknow_api.Core.Models;5 using iknow_api.Repository.Interfaces;6 using iknow_api.Core.Data;7 6 8 namespace iknow_api.Repository7 namespace FinXaccesApi.Repositories 9 8 { 10 9 public class UserRepository : IUserRepository … … 17 16 } 18 17 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) 18 public async Task<bool> UserExistsAsync(string username) 23 19 { 24 await _context.User.AddAsync(user, cancellationToken); 25 await _context.SaveChangesAsync(cancellationToken); 26 return user; 20 return await _context.User.AnyAsync(u => u.Email == username); 27 21 } 28 22 29 public Task<User?> GetUserByIdAsync(int id, CancellationToken cancellationToken = default) 30 => _context.User.FindAsync(new object[] { id }, cancellationToken).AsTask(); 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 } 31 38 } 32 39 } -
iknow-api/Repository/Interface/IUserRepository.cs
rd025ba3 r5b42c8d 1 using System.Threading;2 using System.Threading.Tasks;3 1 using iknow_api.Core.Models; 4 5 namespace iknow_api.Repository.Interfaces 2 namespace FinXaccesApi.Repositories 6 3 { 7 4 public interface IUserRepository 8 5 { 9 Task<bool> EmailExistsAsync(string email, CancellationToken cancellationToken = default); 10 Task<User> AddUserAsync(User user, CancellationToken cancellationToken = default); 11 Task<User?> GetUserByIdAsync(int id, CancellationToken cancellationToken = default); 6 Task<bool> UserExistsAsync(string username); 7 Task<User?> GetUserByUsernameAsync(string username); 8 Task AddUserAsync(User user); 9 Task<int> GetUsersCountAsync(); 12 10 } 13 11 }
Note:
See TracChangeset
for help on using the changeset viewer.
