public static IInvoice InvoiceForInserting(IAddress billTo, decimal total)
        {
            var status = new InvoiceStatus()
                {
                    Key = Constants.DefaultKeys.InvoiceStatus.Unpaid,
                    Active = true,
                    Alias = "unpaid",
                    Name = "Unpaid",
                    SortOrder = 0
                };
            var invoice = new Invoice(status);
            invoice.SetBillingAddress(billTo);
            invoice.Total = total;

            return invoice;
        }
示例#2
0
        /// <summary>
        /// Creates a <see cref="IInvoice"/> without saving it to the database
        /// </summary>
        /// <param name="invoiceStatusKey">The <see cref="IInvoiceStatus"/> key</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns><see cref="IInvoice"/></returns>
        public IInvoice CreateInvoice(Guid invoiceStatusKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(Guid.Empty != invoiceStatusKey, "invoiceStatusKey");

            var status = GetInvoiceStatusByKey(invoiceStatusKey);

            var invoice = new Invoice(status)
                {
                    VersionKey = Guid.NewGuid(),
                    InvoiceDate = DateTime.Now
                };

            if (raiseEvents)
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs<IInvoice>(invoice), this))
                {
                    invoice.WasCancelled = true;
                    return invoice;
                }

            if (raiseEvents) Created.RaiseEvent(new Events.NewEventArgs<IInvoice>(invoice), this);

            return invoice;
        }