Files
nashel-backend/src/Modules/Identity/Infrastructure/Repositories/AccountRepository.cs
Халимов Рустам ee40b38968 Identity
2026-02-09 23:54:03 +03:00

39 lines
1.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using Nashel.Modules.Identity.Domain.Aggregates;
using Nashel.Modules.Identity.Domain.Repositories;
using Nashel.Modules.Identity.Infrastructure.Persistence;
namespace Nashel.Modules.Identity.Infrastructure.Repositories;
public class AccountRepository : IAccountRepository
{
private readonly IdentityDbContext _context;
public AccountRepository(IdentityDbContext context)
{
_context = context;
}
public async Task AddAsync(Account account, CancellationToken cancellationToken)
{
await _context.Accounts.AddAsync(account, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);
}
public async Task<Account?> GetByIdAsync(Guid id, CancellationToken cancellationToken)
{
return await _context.Accounts.FindAsync(new object[] { id }, cancellationToken);
}
public async Task<Account?> GetByPhoneAsync(string phone, CancellationToken cancellationToken)
{
return await _context.Accounts.FirstOrDefaultAsync(a => a.Phone == phone, cancellationToken);
}
public async Task UpdateAsync(Account account, CancellationToken cancellationToken)
{
_context.Accounts.Update(account);
await _context.SaveChangesAsync(cancellationToken);
}
}