Replace the hand-rolled model.Copy(target) pattern in every SaveXxx with FindIndex -> in-place replace (or Add on new). Move the two hidden defaults out of the deleted Copy bodies: Currency = "CHF" default now lives in AccountRepository.SaveAccount; BookingDate = ValueDate default now lives in TransactionRepository.SaveTransaction. Delete Copy from Account, BookingRule, BookingText, SubClass, and SplitPredefinition. Keep Transaction.Clone() (renamed from Copy, and now includes RelatedParty) for the defensive copy in GetTransaction and ViewService.WithDisplaySign. Fixes a pre-existing bug where Transaction.Copy silently dropped RelatedParty on every update save. 42 tests total, all passing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
63 lines
No EOL
1.9 KiB
C#
63 lines
No EOL
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.Extensions.Logging;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
|
|
namespace Schaad.Accounting.Repositories
|
|
{
|
|
public class BookingRuleRepository : BaseRepository, IBookingRuleRepository
|
|
{
|
|
private readonly string BOOKING_RULES = "BookingRules.xml";
|
|
|
|
public BookingRuleRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<BookingRuleRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
EnsureFileExists(BOOKING_RULES);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load booking rules
|
|
/// </summary>
|
|
public List<BookingRule> GetBookingRuleList() => LoadList<BookingRule>(BOOKING_RULES);
|
|
|
|
/// <summary>
|
|
/// Save a booking rule (insert/update)
|
|
/// </summary>
|
|
public void SaveBookingRule(BookingRule bookingRule)
|
|
{
|
|
var bookingRules = GetBookingRuleList();
|
|
var idx = bookingRules.FindIndex(r => r.Id == bookingRule.Id);
|
|
if (idx >= 0)
|
|
{
|
|
bookingRules[idx] = bookingRule;
|
|
}
|
|
else
|
|
{
|
|
bookingRule.Id = Guid.NewGuid().ToString();
|
|
bookingRules.Add(bookingRule);
|
|
}
|
|
Save(bookingRules, BOOKING_RULES);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get booking rule
|
|
/// </summary>
|
|
public BookingRule GetBookingRule(string id)
|
|
{
|
|
var bookingRules = GetBookingRuleList();
|
|
return bookingRules.FirstOrDefault(t => t.Id == id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete booking rule
|
|
/// </summary>
|
|
public void DeleteBookingRule(string id)
|
|
{
|
|
var bookingRules = GetBookingRuleList();
|
|
bookingRules.RemoveAll(t => t.Id == id);
|
|
Save(bookingRules, BOOKING_RULES);
|
|
}
|
|
}
|
|
} |