public static ITry <InvoicesToSubmit, IEnumerable <Error> > Create(Header header, Invoice[] invoices) { return(Try.Aggregate( ObjectValidations.NotNull(header), invoices.OrEmptyIfNull().ToTry(i => i.Count() >= 1 && i.Count() <= 10000, _ => Error.Create($"{nameof(invoices)} count must be in range [1, 10000].")), (h, i) => new InvoicesToSubmit(h, i.ToArray()) )); }
public static ITry <ForeignInvoiceParty, INonEmptyEnumerable <Error> > Create(InvoicePartyInfo info, Country country) { return(ObjectValidations.NotNull(info).FlatMap(i => { var validCountry = country.ToTry(c => c != Countries.Greece, _ => Error.Create($"{nameof(ForeignInvoiceParty)} cannot use greece as a country.")); return validCountry.Map(c => new ForeignInvoiceParty(i, c)); })); }
public static ITry <InvoiceInfo, INonEmptyEnumerable <Error> > Create(InvoiceHeader header, InvoiceParty issuer) { return(ObjectValidations.NotNull(header).FlatMap(h => { var validIssuer = ObjectValidations.NotNull(issuer); return validIssuer.Map(i => new InvoiceInfo(h, i)); })); }
public static ITry <NegativeRevenue, IEnumerable <Error> > Create(NegativeAmount netValue, NonPositiveAmount vatValue, RevenueInfo info) { return(Try.Aggregate( ObjectValidations.NotNull(netValue), ObjectValidations.NotNull(vatValue), ObjectValidations.NotNull(info), (n, v, i) => new NegativeRevenue(n, v, i) )); }
public static ITry <RetailSalesReceipt, IEnumerable <Error> > Create(InvoiceInfo info, ISequenceStartingWithOne <NonNegativeRevenue> revenueItems, INonEmptyEnumerable <NonNegativePayment> payments) { return(Try.Aggregate( ObjectValidations.NotNull(info), ObjectValidations.NotNull(revenueItems), ObjectValidations.NotNull(payments), (i, r, p) => new RetailSalesReceipt(i, r, p) )); }
public static ITry <SalesInvoice, IEnumerable <Error> > Create( InvoiceInfo info, ISequenceStartingWithOne <NonNegativeRevenue> revenueItems, INonEmptyEnumerable <NonNegativePayment> payments, InvoiceParty counterpart) { return(Try.Aggregate( ObjectValidations.NotNull(info), ObjectValidations.NotNull(revenueItems), ObjectValidations.NotNull(payments), ObjectValidations.NotNull(counterpart), (i, r, p, c) => new SalesInvoice(i, r, p, c) )); }
public static ITry <SimplifiedInvoice, IEnumerable <Error> > Create(InvoiceInfo info, ISequenceStartingWithOne <NonNegativeRevenue> revenueItems, INonEmptyEnumerable <NonNegativePayment> payments) { var result = Try.Aggregate( ObjectValidations.NotNull(info), ObjectValidations.NotNull(revenueItems), ObjectValidations.NotNull(payments), (i, r, p) => IsValidSimplifiedInvoice(i, r).ToTry( t => new SimplifiedInvoice(i, r, p), f => new Error($"{nameof(SimplifiedInvoice)} can only be below or equal to 100 EUR.").ToEnumerable() ) ); return(result.FlatMap(r => r)); }
public static ITry <CreditInvoice, IEnumerable <Error> > Create( InvoiceInfo info, ISequenceStartingWithOne <NegativeRevenue> revenueItems, INonEmptyEnumerable <NegativePayment> payments, InvoiceParty counterPart, long?correlatedInvoice = null) { return(Try.Aggregate( ObjectValidations.NotNull(info), ObjectValidations.NotNull(revenueItems), ObjectValidations.NotNull(payments), ObjectValidations.NotNull(counterPart), (i, r, p, c) => new CreditInvoice(i, r, p, c, correlatedInvoice) )); }
public static ITry <InvoiceParty, INonEmptyEnumerable <Error> > Create(InvoicePartyInfo info, Country country) { return(ObjectValidations.NotNull(country).FlatMap(c => { var validatedInfo = ObjectValidations.NotNull(info); return validatedInfo.FlatMap(i => { if (c == Countries.Greece) { return LocalInvoiceParty.Create(i).Map(p => new InvoiceParty(p)); } return ForeignInvoiceParty.Create(i, c).Map(p => new InvoiceParty(p)); }); })); }
public static ITry <InvoicePartyInfo, INonEmptyEnumerable <Error> > Create(NonNegativeInt?branch = null, TaxpayerIdentificationNumber taxpayerNumber = null, string name = null, Address address = null) { return(ObjectValidations.NotNull(branch).Map(b => new InvoicePartyInfo(b ?? NonNegativeInt.Zero(), taxpayerNumber, name, address))); }
/// <summary> /// Returns all object validations containing validation items of a specific type. /// </summary> /// <param name="validationType">The validation type.</param> /// <returns>List of object validations containing validation items of a matching type.</returns> public IEnumerable <ObjectValidation> GetValidationsOfType(ValidationTypes validationType) { return(ObjectValidations.Where(ov => ov.Validations.Any(v => v.ValidationType == validationType))); }
public static ITry <NegativePayment, INonEmptyEnumerable <Error> > Create(NegativeAmount amount, PaymentType paymentType) { return(ObjectValidations.NotNull(amount).Map(a => new NegativePayment(a, paymentType))); }
public static ITry <LocalInvoiceParty, INonEmptyEnumerable <Error> > Create(InvoicePartyInfo info) { return(ObjectValidations.NotNull(info).Map(i => new LocalInvoiceParty(i, Countries.Greece))); }
/// <summary> /// Determines if any of the object validation items are of the specified validation level. /// </summary> /// <param name="validationType">The validation level to check.</param> /// <returns>True of if there is a validation of the specified type.</returns> public bool Contains(ValidationTypes validationType) { return(ObjectValidations.Any(v => v.ValidationType == validationType)); }