50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Shared.Contracts.Account;
|
|
|
|
namespace AccountMangement.Infrastructure.EFCore.Services;
|
|
|
|
public class AccountQueryService : IAccountQueryService
|
|
{
|
|
private readonly AccountContext _accountContext;
|
|
|
|
public AccountQueryService(AccountContext accountContext)
|
|
{
|
|
_accountContext = accountContext;
|
|
}
|
|
|
|
public async Task<AccountBasicDto> GetAccountAsync(long accountId)
|
|
{
|
|
return await _accountContext.Accounts
|
|
.Where(x => x.id == accountId)
|
|
.Select(x => new AccountBasicDto
|
|
{
|
|
Id = x.id,
|
|
Username = x.Username,
|
|
Fullname = x.Fullname,
|
|
IsActive = x.IsActiveString == "true"
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
}
|
|
|
|
public async Task<List<AccountBasicDto>> GetProgramManagerAccountListAsync(List<long> accountIds)
|
|
{
|
|
var ids = accountIds?.ToHashSet() ?? new HashSet<long>();
|
|
if (ids.Count == 0)
|
|
return [];
|
|
|
|
return await _accountContext.Accounts
|
|
.Where(x => ids.Contains(x.id))
|
|
.Select(x => new AccountBasicDto
|
|
{
|
|
Id = x.id,
|
|
Username = x.Username,
|
|
Fullname = x.Fullname,
|
|
IsActive = x.IsActiveString == "true"
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
}
|