AccountingNext/Schaad.Accounting.Db/Repositories/ElectricityBillRepository.cs
Claudio Schaad a6e479094e Add "Strom" page for the yearly NeoVac electricity bills (#9)
Co-authored-by: Claudio Schaad <c.schaad@pog.ch>
Co-committed-by: Claudio Schaad <c.schaad@pog.ch>
2026-10-27 18:40:53 +00:00

56 lines
2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>
/// Electricity bills of the current mandator, stored once per mandator (not per year like
/// the other data files) because the billing period runs 1 July – 30 June.
/// </summary>
public class ElectricityBillRepository : BaseRepository, IElectricityBillRepository
{
private const string ELECTRICITY = "electricity.json";
public ElectricityBillRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<ElectricityBillRepository> logger)
: base(settingsService, cache, logger)
{
}
public Task<List<ElectricityBill>> GetElectricityBillListAsync()
=> LoadListAsync<ElectricityBill>(settingsService.GetMandatorPath(), ELECTRICITY);
public async Task SaveElectricityBillAsync(ElectricityBill bill)
{
var bills = await GetElectricityBillListAsync();
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(), ELECTRICITY);
}
public async Task<ElectricityBill> GetElectricityBillAsync(string id)
{
var bills = await GetElectricityBillListAsync();
return bills.FirstOrDefault(b => b.Id == id);
}
public async Task DeleteElectricityBillAsync(string id)
{
var bills = await GetElectricityBillListAsync();
bills.RemoveAll(b => b.Id == id);
await SaveAsync(bills, settingsService.GetMandatorPath(), ELECTRICITY);
}
}
}