Example #1
0
        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));
                });
            }));
        }
Example #2
0
 private LocalInvoiceParty(InvoicePartyInfo info, Country country)
 {
     Info    = info;
     Country = country;
 }
 private ForeignInvoiceParty(InvoicePartyInfo info, Country country)
 {
     Country = country;
     Info    = info;
 }
Example #4
0
 public static ITry <LocalInvoiceParty, INonEmptyEnumerable <Error> > Create(InvoicePartyInfo info)
 {
     return(ObjectValidations.NotNull(info).Map(i => new LocalInvoiceParty(i, Countries.Greece)));
 }
 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));
     }));
 }