Add accounts page
This commit is contained in:
30
Hcs.WebApp/Services/AccountService.cs
Normal file
30
Hcs.WebApp/Services/AccountService.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using EFCore.BulkExtensions;
|
||||
using Hcs.WebApp.Data.Hcs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hcs.WebApp.Services
|
||||
{
|
||||
public class AccountService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
||||
{
|
||||
public async Task<IEnumerable<Account>> GetAllAccountsAsync()
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
return await context.Accounts.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task UpsertAccounts(HcsDbContext context, IEnumerable<Account> accounts)
|
||||
{
|
||||
await context.BulkInsertOrUpdateAsync(accounts, new BulkConfig()
|
||||
{
|
||||
PropertiesToExcludeOnUpdate =
|
||||
[
|
||||
nameof(SupplyContract.ThirdPartyId)
|
||||
],
|
||||
UpdateByProperties =
|
||||
[
|
||||
nameof(SupplyContract.HcsId)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user