31 lines
977 B
C#
31 lines
977 B
C#
using EFCore.BulkExtensions;
|
|
using Hcs.WebApp.Data.Hcs;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Hcs.WebApp.Services
|
|
{
|
|
public class SupplyContractService(IDbContextFactory<HcsDbContext> factory) : HcsServiceBase(factory)
|
|
{
|
|
public async Task<IEnumerable<SupplyContract>> GetAllSupplyContractsAsync()
|
|
{
|
|
using var context = GetNewContext();
|
|
return await context.SupplyContracts.ToListAsync();
|
|
}
|
|
|
|
public async Task UpsertSupplyContracts(HcsDbContext context, IEnumerable<SupplyContract> supplyContracts)
|
|
{
|
|
await context.BulkInsertOrUpdateAsync(supplyContracts, new BulkConfig()
|
|
{
|
|
PropertiesToExcludeOnUpdate =
|
|
[
|
|
nameof(SupplyContract.ThirdPartyId)
|
|
],
|
|
UpdateByProperties =
|
|
[
|
|
nameof(SupplyContract.HcsId)
|
|
]
|
|
});
|
|
}
|
|
}
|
|
}
|