Files
BeWoPlaner/Shared/Core/ValidatorExtended.cs
2024-12-06 13:05:28 +01:00

47 lines
1.2 KiB
C#

using BS.Shared.DataContracts;
using BS.Shared.DataContracts.GkvAbrechnung;
using BS.Shared.Exceptions;
using BS.Shared.Extensions;
using BS.Shared.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BS.Shared.Core
{
public static class ValidatorExtended
{
public static void ValidateGkvAbrechnung(IGkvAbrechnung gkvAbrechnung, IEnumerable<IInvoiceBase> invoiceBases, bool testInvoicesEmpty = true)
{
string error = null;
if (testInvoicesEmpty && !invoiceBases.Any())
error = "Keine Rechnungen gefunden";
else if (!AreAllAddressSame(invoiceBases))
error = "Unterschiedliche Rechnungspositionen";
if(error is string)
throw new GkvException(error, "Validierung");
}
public static bool TryValidateGkvAbrechnung(IGkvAbrechnung gkvAbrechnung, IEnumerable<IInvoiceBase> invoiceBases, bool testInvoicesEmpty = true)
{
try
{
ValidateGkvAbrechnung(gkvAbrechnung, invoiceBases, testInvoicesEmpty);
}
catch (Exception)
{
return false;
}
return true;
}
public static bool AreAllAddressSame(IEnumerable<IInvoiceBase> invoiceBases)
=> invoiceBases.Select(x => x.SenderAddressToString()).AreAllTheSame();
}
}