- Consolidate decimal.ToFormattedString into Schaad.Accounting.Formatting - Rename EnsureFileExisits -> EnsureFileExists and SplitPredefiniton* -> SplitPredefinition* (class, interface, files, DI reg) - AccountRepository: single-save year-rollover start-balance seed - Drop legacy .NET Standard packages redundant on net9.0 and the stale Interfaces\Extensions\ folder entry - Set culture via RequestLocalizationOptions middleware - Plan: item 9 (unit of work) split off into a dedicated PR D Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
64 lines
No EOL
1.9 KiB
C#
64 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 BookingRuleRepository : BaseRepository, IBookingRuleRepository
|
|
{
|
|
private readonly string BOOKING_RULES = "BookingRules.xml";
|
|
|
|
public BookingRuleRepository(ISettingsService settingsService) : base(settingsService)
|
|
{
|
|
EnsureFileExists(BOOKING_RULES);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load booking rules
|
|
/// </summary>
|
|
public List<BookingRule> GetBookingRuleList()
|
|
{
|
|
var bookingTexts = Load<List<BookingRule>>(BOOKING_RULES);
|
|
return bookingTexts ?? new List<BookingRule>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Save a booking rule (insert/update)
|
|
/// </summary>
|
|
public void SaveBookingRule(BookingRule bookingRule)
|
|
{
|
|
var bookingRules = GetBookingRuleList();
|
|
var existingRule = bookingRules.FirstOrDefault(a => a.Id == bookingRule.Id);
|
|
|
|
if (existingRule == null)
|
|
{
|
|
existingRule = new BookingRule();
|
|
bookingRules.Add(existingRule);
|
|
bookingRule.Id = Guid.NewGuid().ToString();
|
|
}
|
|
bookingRule.Copy(existingRule);
|
|
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);
|
|
}
|
|
}
|
|
} |