Add supply contracts page
This commit is contained in:
31
Hcs.WebApp/Services/SupplyContractService.cs
Normal file
31
Hcs.WebApp/Services/SupplyContractService.cs
Normal file
@ -0,0 +1,31 @@
|
||||
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(IEnumerable<SupplyContract> supplyContracts)
|
||||
{
|
||||
using var context = GetNewContext();
|
||||
await context.BulkInsertOrUpdateAsync(supplyContracts, new BulkConfig()
|
||||
{
|
||||
PropertiesToExcludeOnUpdate =
|
||||
[
|
||||
nameof(SupplyContract.ThirdPartyId)
|
||||
],
|
||||
UpdateByProperties =
|
||||
[
|
||||
nameof(SupplyContract.HcsId)
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user