Esempio n. 1
0
        /// <summary>
        /// Generates an <see cref="IInvoice"/> representing the bill for the current "checkout order"
        /// </summary>
        /// <param name="invoiceBuilder">The invoice builder class</param>
        /// <returns>An <see cref="IInvoice"/> that is not persisted to the database.</returns>
        public IInvoice PrepareInvoice(IBuilderChain <IInvoice> invoiceBuilder)
        {
            if (!IsReadyToInvoice())
            {
                return(null);
            }

            var attempt = invoiceBuilder.Build();

            if (!attempt.Success)
            {
                LogHelper.Error <SalePreparationBase>("The invoice builder failed to generate an invoice.", attempt.Exception);
                throw attempt.Exception;
            }

            return(attempt.Result);
        }
Esempio n. 2
0
        /// <summary>
        /// Prepares an <see cref="IOrder"/> without saving it to the database.
        /// </summary>
        /// <param name="invoice">The <see cref="IInvoice"/> to base the order on</param>
        /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param>
        /// <param name="orderBuilder">The <see cref="IBuilderChain{IOrder}"/></param>
        /// <returns>The <see cref="IOrder"/></returns>
        /// <remarks>
        ///
        /// This method will save the invoice in the event it has not previously been saved
        ///
        /// </remarks>
        public static IOrder PrepareOrder(this IInvoice invoice, IMerchelloContext merchelloContext,
                                          IBuilderChain <IOrder> orderBuilder)
        {
            if (!invoice.HasIdentity)
            {
                merchelloContext.Services.InvoiceService.Save(invoice);
            }

            var attempt = orderBuilder.Build();

            if (attempt.Success)
            {
                return(attempt.Result);
            }

            LogHelper.Error <OrderBuilderChain>("Extension method PrepareOrder failed", attempt.Exception);
            throw attempt.Exception;
        }
        /// <summary>
        /// Generates an <see cref="IInvoice"/> representing the bill for the current "checkout order"
        /// </summary>
        /// <param name="invoiceBuilder">The invoice builder class</param>
        /// <returns>An <see cref="IInvoice"/> that is not persisted to the database.</returns>
        public IInvoice PrepareInvoice(IBuilderChain <IInvoice> invoiceBuilder)
        {
            if (!IsReadyToInvoice())
            {
                return(null);
            }

            var attempt = invoiceBuilder.Build();

            if (attempt.Success)
            {
                InvoicePrepared.RaiseEvent(new SalesPreparationEventArgs <IInvoice>(attempt.Result), this);

                return(attempt.Result);
            }

            LogHelper.Error <SalePreparationBase>("The invoice builder failed to generate an invoice.", attempt.Exception);

            throw attempt.Exception;
        }
        /// <summary>
        /// Generates an <see cref="IInvoice"/> representing the bill for the current "checkout order"
        /// </summary>
        /// <param name="invoiceBuilder">The invoice builder class</param>
        /// <returns>An <see cref="IInvoice"/> that is not persisted to the database.</returns>
        public virtual IInvoice PrepareInvoice(IBuilderChain <IInvoice> invoiceBuilder)
        {
            if (!IsReadyToInvoice())
            {
                return(null);
            }

            ////var requestCache = _merchelloContext.Cache.RequestCache;
            ////var cacheKey = string.Format("merchello.salespreparationbase.prepareinvoice.{0}", ItemCache.VersionKey);
            var attempt = invoiceBuilder.Build();

            if (attempt.Success)
            {
                InvoicePrepared.RaiseEvent(new CheckoutEventArgs <IInvoice>(Context.Customer, attempt.Result), this);

                return(attempt.Result);
            }

            LogHelper.Error <SalePreparationBase>("The invoice builder failed to generate an invoice.", attempt.Exception);

            throw attempt.Exception;
        }
Esempio n. 5
0
        /// <summary>
        /// Generates an <see cref="IInvoice"/> representing the bill for the current "checkout order"
        /// </summary>
        /// <param name="invoiceBuilder">The invoice builder class</param>
        /// <returns>An <see cref="IInvoice"/> that is not persisted to the database.</returns>
        public IInvoice PrepareInvoice(IBuilderChain<IInvoice> invoiceBuilder)
        {
            if (!IsReadyToInvoice()) return null;

            var attempt = invoiceBuilder.Build();

            if (attempt.Success) return attempt.Result;

            LogHelper.Error<SalePreparationBase>("The invoice builder failed to generate an invoice.", attempt.Exception);

            throw attempt.Exception;
        }
Esempio n. 6
0
        /// <summary>
        /// Prepares an <see cref="IOrder"/> without saving it to the database.  
        /// </summary>
        /// <param name="invoice">The <see cref="IInvoice"/> to base the order on</param>
        /// <param name="merchelloContext">The <see cref="IMerchelloContext"/></param>
        /// <param name="orderBuilder">The <see cref="IBuilderChain{IOrder}"/></param>
        /// <returns>The <see cref="IOrder"/></returns>
        /// <remarks>
        /// 
        /// This method will save the invoice in the event it has not previously been saved
        /// 
        /// </remarks>
        public static IOrder PrepareOrder(
            this IInvoice invoice,
            IMerchelloContext merchelloContext,
            IBuilderChain<IOrder> orderBuilder)
        {
            if (!invoice.HasIdentity) merchelloContext.Services.InvoiceService.Save(invoice);

            var attempt = orderBuilder.Build();
            if (attempt.Success) return attempt.Result;

            LogHelper.Error<OrderBuilderChain>("Extension method PrepareOrder failed", attempt.Exception);
            throw attempt.Exception;
        }
        /// <summary>
        /// Generates an <see cref="IInvoice"/> representing the bill for the current "checkout order"
        /// </summary>
        /// <param name="invoiceBuilder">The invoice builder class</param>
        /// <returns>An <see cref="IInvoice"/> that is not persisted to the database.</returns>
        public virtual IInvoice PrepareInvoice(IBuilderChain<IInvoice> invoiceBuilder)
        {
            if (!IsReadyToInvoice()) return null;

            ////var requestCache = _merchelloContext.Cache.RequestCache;
            ////var cacheKey = string.Format("merchello.salespreparationbase.prepareinvoice.{0}", ItemCache.VersionKey);
            var attempt = invoiceBuilder.Build();

            if (attempt.Success)
            {
                InvoicePrepared.RaiseEvent(new CheckoutEventArgs<IInvoice>(Context.Customer, attempt.Result), this);

                return attempt.Result;
            }

            LogHelper.Error<SalePreparationBase>("The invoice builder failed to generate an invoice.", attempt.Exception);

            throw attempt.Exception;
        }