예제 #1
0
        public static IInvoiceBuilder AddMellatCumulativeAccounts(this IInvoiceBuilder builder, IEnumerable <MellatCumulativeDynamicAccount> accounts)
        {
            if (accounts == null)
            {
                throw new ArgumentNullException(nameof(accounts));
            }
            if (!accounts.Any())
            {
                throw new ArgumentException("Accounts cannot be an empty collection.", nameof(accounts));
            }

            List <MellatCumulativeDynamicAccount> allAccounts = null;

            builder.ChangeProperties(properties =>
            {
                if (properties.ContainsKey(MellatHelper.CumulativeAccountsKey))
                {
                    allAccounts = (List <MellatCumulativeDynamicAccount>)properties[MellatHelper.CumulativeAccountsKey];
                }
                else
                {
                    allAccounts = new List <MellatCumulativeDynamicAccount>();

                    properties.Add(MellatHelper.CumulativeAccountsKey, allAccounts);
                }

                allAccounts.AddRange(accounts);
            });

            return(builder);
        }