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>
44 lines
1.5 KiB
C#
44 lines
1.5 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 SplitPredefinitionRepository : BaseRepository, ISplitPredefinitionRepository
|
|
{
|
|
private readonly string SPLIT_PREDEFINITION = "SplitPredefinitions.xml";
|
|
|
|
public SplitPredefinitionRepository(ISettingsService settingsService, RepositoryCache cache, ILogger<SplitPredefinitionRepository> logger)
|
|
: base(settingsService, cache, logger)
|
|
{
|
|
EnsureFileExists(SPLIT_PREDEFINITION);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load split predefinitions
|
|
/// </summary>
|
|
public List<SplitPredefinition> GetSplitPredefinitionList() => LoadList<SplitPredefinition>(SPLIT_PREDEFINITION);
|
|
|
|
/// <summary>
|
|
/// Save a split predefinition (insert/update)
|
|
/// </summary>
|
|
public void SaveSplitPredefinition(SplitPredefinition splitPredefinition)
|
|
{
|
|
var definitions = GetSplitPredefinitionList();
|
|
var idx = definitions.FindIndex(d => d.Id == splitPredefinition.Id);
|
|
if (idx >= 0)
|
|
{
|
|
definitions[idx] = splitPredefinition;
|
|
}
|
|
else
|
|
{
|
|
splitPredefinition.Id = Guid.NewGuid().ToString();
|
|
definitions.Add(splitPredefinition);
|
|
}
|
|
Save(definitions, SPLIT_PREDEFINITION);
|
|
}
|
|
}
|
|
}
|