Co-authored-by: Claudio Schaad <c.schaad@pog.ch> Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
56 lines
2 KiB
C#
56 lines
2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Repositories
|
|
{
|
|
/// <summary>
|
|
/// NeoVac water and heating bills of the current mandator, stored once per mandator (not per
|
|
/// year like the other data files) because the billing period doesn't align with calendar years.
|
|
/// </summary>
|
|
public class WaterHeatingBillRepository : BaseRepository, IWaterHeatingBillRepository
|
|
{
|
|
private const string WATER_HEATING = "water-heating.json";
|
|
|
|
public WaterHeatingBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<WaterHeatingBillRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
}
|
|
|
|
public Task<List<WaterHeatingBill>> GetWaterHeatingBillListAsync()
|
|
=> LoadListAsync<WaterHeatingBill>(settingsService.GetMandatorPath(), WATER_HEATING);
|
|
|
|
public async Task SaveWaterHeatingBillAsync(WaterHeatingBill bill)
|
|
{
|
|
var bills = await GetWaterHeatingBillListAsync();
|
|
var idx = bills.FindIndex(b => b.Id == bill.Id);
|
|
if (idx >= 0)
|
|
{
|
|
bills[idx] = bill;
|
|
}
|
|
else
|
|
{
|
|
bill.Id = Guid.NewGuid().ToString();
|
|
bills.Add(bill);
|
|
}
|
|
await SaveAsync(bills, settingsService.GetMandatorPath(), WATER_HEATING);
|
|
}
|
|
|
|
public async Task<WaterHeatingBill> GetWaterHeatingBillAsync(string id)
|
|
{
|
|
var bills = await GetWaterHeatingBillListAsync();
|
|
return bills.FirstOrDefault(b => b.Id == id);
|
|
}
|
|
|
|
public async Task DeleteWaterHeatingBillAsync(string id)
|
|
{
|
|
var bills = await GetWaterHeatingBillListAsync();
|
|
bills.RemoveAll(b => b.Id == id);
|
|
await SaveAsync(bills, settingsService.GetMandatorPath(), WATER_HEATING);
|
|
}
|
|
}
|
|
}
|