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 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 invoiceBases, bool testInvoicesEmpty = true) { try { ValidateGkvAbrechnung(gkvAbrechnung, invoiceBases, testInvoicesEmpty); } catch (Exception) { return false; } return true; } public static bool AreAllAddressSame(IEnumerable invoiceBases) => invoiceBases.Select(x => x.SenderAddressToString()).AreAllTheSame(); } }