Add a Scoped RepositoryCache that memoizes deserialized XML lists, keyed by absolute file path. Each XML file is loaded at most once per SignalR circuit; Save invalidates the corresponding entry so subsequent reads reload from disk. BaseRepository gains a LoadList<T>(fileName) helper; each of the seven repositories now defines Get*List() as a one-liner over that helper and takes RepositoryCache via the constructor. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
61 lines
No EOL
1.9 KiB
C#
61 lines
No EOL
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Repositories
|
|
{
|
|
public class BookingTextRepository : BaseRepository, IBookingTextRepository
|
|
{
|
|
private readonly string BOOKING_TEXTS = "BookingTexts.xml";
|
|
|
|
public BookingTextRepository(ISettingsService settingsService, RepositoryCache cache)
|
|
: base(settingsService, cache)
|
|
{
|
|
EnsureFileExists(BOOKING_TEXTS);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load booking texts
|
|
/// </summary>
|
|
public List<BookingText> GetBookingTextList() => LoadList<BookingText>(BOOKING_TEXTS);
|
|
|
|
/// <summary>
|
|
/// Save a booking text (insert/update)
|
|
/// </summary>
|
|
public void SaveBookingText(BookingText bookingText)
|
|
{
|
|
var bookingTexts = GetBookingTextList();
|
|
var existingText = bookingTexts.FirstOrDefault(a => a.Id == bookingText.Id);
|
|
|
|
if (existingText == null)
|
|
{
|
|
existingText = new BookingText();
|
|
bookingTexts.Add(existingText);
|
|
bookingText.Id = Guid.NewGuid().ToString();
|
|
}
|
|
bookingText.Copy(existingText);
|
|
Save(bookingTexts, BOOKING_TEXTS);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get booking text
|
|
/// </summary>
|
|
public BookingText GetBookingText(string id)
|
|
{
|
|
var bookingTexts = GetBookingTextList();
|
|
return bookingTexts.FirstOrDefault(t => t.Id == id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete booking text
|
|
/// </summary>
|
|
public void DeleteBookingText(string id)
|
|
{
|
|
var bookingTexts = GetBookingTextList();
|
|
bookingTexts.RemoveAll(t => t.Id == id);
|
|
Save(bookingTexts, BOOKING_TEXTS);
|
|
}
|
|
}
|
|
} |