Exemple #1
0
        public void MarkAsReserved(IPricingService pricingService, DateTime expirationDate, IEnumerable <AnchorQuantity> reservedAnchors)
        {
            if (this.isConfirmed)
            {
                throw new InvalidOperationException("Cannot modify a confirmed order.");
            }

            var reserved = reservedAnchors.ToList();

            // Is there an order item which didn't get an exact reservation?
            if (this.anchors.Any(item => item.Quantity != 0 && !reserved.Any(anchor => anchor.AnchorType == item.AnchorType && anchor.Quantity == item.Quantity)))
            {
                var totals = pricingService.CalculateTotal(this.workshopId, reserved.AsReadOnly());

                this.Update(new OrderPartiallyReserved {
                    ReservationExpiration = expirationDate, Anchors = reserved.ToArray()
                });
                //TODO: IsFreeOfCharge back to normal calculations: totals.Total == 0m
                this.Update(new OrderTotalsCalculated {
                    Total = totals.Total, Lines = totals.Lines != null ? totals.Lines.ToArray() : null, IsFreeOfCharge = true
                });
            }
            else
            {
                this.Update(new OrderReservationCompleted {
                    ReservationExpiration = expirationDate, Anchors = reserved.ToArray()
                });
            }
        }
Exemple #2
0
        public void MarkAsReserved(IPricingService pricingService, DateTime expirationDate,
                                   IEnumerable <SeatQuantity> reservedSeats)
        {
            if (this.isConfirmed)
            {
                throw new InvalidOperationException("Cannot modify a confirmed order.");
            }

            var reserved = reservedSeats.ToList();

            // Is there an order item which didn't get an exact reservation?
            if (this.seats.Any(item =>
                               item.Quantity != 0 &&
                               !reserved.Any(seat => seat.SeatType == item.SeatType && seat.Quantity == item.Quantity)))
            {
                var totals = pricingService.CalculateTotal(this.conferenceId, reserved.AsReadOnly()).Result;

                this.Update(new OrderPartiallyReserved
                {
                    ReservationExpiration = expirationDate, Seats = reserved.ToArray()
                });
                this.Update(new OrderTotalsCalculated
                {
                    Total          = totals.Total, Lines = totals.Lines?.ToArray(),
                    IsFreeOfCharge = totals.Total == 0m
                });
            }
            else
            {
                this.Update(new OrderReservationCompleted
                {
                    ReservationExpiration = expirationDate, Seats = reserved.ToArray()
                });
            }
        }
Exemple #3
0
        /// <summary>
        /// Updates the order with the specified items.
        /// </summary>
        /// <param name="items">The desired seats to register to.</param>
        /// <param name="pricingService">Service that calculates the pricing.</param>
        public void UpdateSeats(IEnumerable <OrderItem> items, IPricingService pricingService)
        {
            var all    = ConvertItems(items);
            var totals = pricingService.CalculateTotal(this.conferenceId, all.AsReadOnly());

            this.Update(new OrderUpdated {
                Seats = all
            });
            this.Update(new OrderTotalsCalculated {
                Total = totals.Total, Lines = totals.Lines != null ? totals.Lines.ToArray() : null, IsFreeOfCharge = totals.Total == 0m
            });
        }
Exemple #4
0
        /// <summary>
        /// Updates the order with the specified items.
        /// </summary>
        /// <remarks>
        /// The total is now calculated at this time. This was a change done in the V3 version of the system to optimize
        /// the UI workflow.
        /// See <see cref="http://go.microsoft.com/fwlink/p/?LinkID=258557"> Journey chapter 7</see> for more information on
        /// the optimization and migration to V3.
        /// </remarks>
        /// <param name="items">The desired anchors to register to.</param>
        /// <param name="pricingService">Service that calculates the pricing.</param>
        public void UpdateAnchors(IEnumerable <OrderItem> items, IPricingService pricingService)
        {
            var all    = ConvertItems(items);
            var totals = pricingService.CalculateTotal(this.workshopId, all.AsReadOnly());

            this.Update(new OrderUpdated {
                Anchors = all
            });
            //TODO: IsFreeOfCharge back to normal calculations: totals.Total == 0m
            this.Update(new OrderTotalsCalculated {
                Total = totals.Total, Lines = totals.Lines != null ? totals.Lines.ToArray() : null, IsFreeOfCharge = true
            });
        }
Exemple #5
0
        public Order(Guid id, Guid conferenceId, IEnumerable <SeatQuantity> seats, IPricingService pricingService) : base(id)
        {
            Ensure.NotEmptyGuid(id, "id");
            Ensure.NotEmptyGuid(conferenceId, "conferenceId");
            Ensure.NotNull(seats, "seats");
            Ensure.NotNull(pricingService, "pricingService");
            if (!seats.Any())
            {
                throw new ArgumentException("The seats of order cannot be empty.");
            }

            var orderTotal = pricingService.CalculateTotal(conferenceId, seats);

            ApplyEvent(new OrderPlaced(this, conferenceId, orderTotal, DateTime.UtcNow.Add(ConfigSettings.ReservationAutoExpiration), ObjectId.GenerateNewStringId()));
        }
Exemple #6
0
        public Order(Guid id, Guid conferenceId, IEnumerable <OrderItem> items, IPricingService pricingService) : this(id) {
            var all    = ConvertItems(items);
            var totals = pricingService.CalculateTotal(conferenceId, all.AsReadOnly());

            this.Update(new OrderPlaced {
                ConferenceId = conferenceId,
                Seats        = all,
                ReservationAutoExpiration = DateTime.UtcNow.Add(ReservationAutoExpiration),
                AccessCode = HandleGenerator.Generate(6)
            });
            this.Update(new OrderTotalsCalculated {
                Total          = totals.Total,
                Lines          = totals.Lines != null ? totals.Lines.ToArray() : null,
                IsFreeOfCharge = totals.Total == 0m
            });
        }
Exemple #7
0
        /// <summary>
        /// Creates a new order with the specified items and id.
        /// </summary>
        /// <remarks>
        /// The total is calculated at creation time. This was a change done in the V3 version of the system to optimize
        /// the UI workflow.
        /// See <see cref="http://go.microsoft.com/fwlink/p/?LinkID=258557"> Journey chapter 7</see> for more information on
        /// the optimization and migration to V3.
        /// </remarks>
        /// <param name="id">The identifier.</param>
        /// <param name="workshopId">The conference that the order applies to.</param>
        /// <param name="items">The desired anchors to register to.</param>
        /// <param name="pricingService">Service that calculates the pricing.</param>
        public Order(Guid id, Guid workshopId, IEnumerable <OrderItem> items, IPricingService pricingService)
            : this(id)
        {
            var all    = ConvertItems(items);
            var totals = pricingService.CalculateTotal(workshopId, all.AsReadOnly());

            this.Update(new OrderPlaced
            {
                WorkshopId = workshopId,
                Anchors    = all,
                ReservationAutoExpiration = DateTime.UtcNow.Add(ReservationAutoExpiration),
                AccessCode = HandleGenerator.Generate(6)
            });
            //TODO: IsFreeOfCharge back to normal calculations: totals.Total == 0m
            this.Update(new OrderTotalsCalculated {
                Total = totals.Total, Lines = totals.Lines != null ? totals.Lines.ToArray() : null, IsFreeOfCharge = true
            });
        }
        public void MarkAsReserved(IPricingService pricingService, DateTime expirationDate, IEnumerable<SeatQuantity> reservedSeats)
        {
            if (this.isConfirmed)
                throw new InvalidOperationException("Cannot modify a confirmed order.");

            var reserved = reservedSeats.ToList();

            var totals = pricingService.CalculateTotal(this.conferenceId, reserved.AsReadOnly());

            // Is there an order item which didn't get an exact reservation?
            if (this.seats.Any(item => item.Quantity != 0 && !reserved.Any(seat => seat.SeatType == item.SeatType && seat.Quantity == item.Quantity)))
            {
                this.Update(new OrderPartiallyReserved { ReservationExpiration = expirationDate, Seats = reserved.ToArray() });
            }
            else
            {
                this.Update(new OrderReservationCompleted { ReservationExpiration = expirationDate, Seats = reserved.ToArray() });
            }

            this.Update(new OrderTotalsCalculated { Total = totals.Total, Lines = totals.Lines.ToArray(), IsFreeOfCharge = totals.Total == 0m });
        }
Exemple #9
0
        private static readonly TimeSpan PollInterval = TimeSpan.FromMinutes(2);//每半小时轮询付款状态


        public Order(Guid id,
                     Guid userId,
                     ExpressAddressInfo expressAddressInfo,
                     IEnumerable <SpecificationQuantity> specifications,
                     IPricingService pricingService) : base(id)
        {
            Ensure.NotEmptyGuid(id, nameof(id));
            Ensure.NotNull(specifications, nameof(specifications));
            Ensure.NotNull(pricingService, nameof(pricingService));

            if (!specifications.Any())
            {
                throw new ArgumentException("订单的商品不能为空");
            }

            var orderTotal = pricingService.CalculateTotal(specifications);

            ApplyEvent(new OrderPlacedEvent(userId,
                                            expressAddressInfo,
                                            orderTotal,
                                            DateTime.Now.Add(ConfigSettings.ReservationAutoExpiration)));
        }
Exemple #10
0
        /// <summary>
        /// Creates a new order with the specified items and id.
        /// </summary>
        /// <remarks>
        /// The total is calculated at creation time. This was a change done in the V3 version of the system to optimize 
        /// the UI workflow. 
        /// See <see cref="http://go.microsoft.com/fwlink/p/?LinkID=258557"> Journey chapter 7</see> for more information on 
        /// the optimization and migration to V3.
        /// </remarks>
        /// <param name="id">The identifier.</param>
        /// <param name="conferenceId">The conference that the order applies to.</param>
        /// <param name="items">The desired seats to register to.</param>
        /// <param name="pricingService">Service that calculates the pricing.</param>
        public Order(Guid id, Guid conferenceId, IEnumerable<OrderItem> items, IPricingService pricingService)
            : this(id)
        {
            var all = ConvertItems(items);
            var totals = pricingService.CalculateTotal(conferenceId, all.AsReadOnly());

            this.Update(new OrderPlaced
            {
                ConferenceId = conferenceId,
                Seats = all,
                ReservationAutoExpiration = DateTime.UtcNow.Add(ReservationAutoExpiration),
                AccessCode = HandleGenerator.Generate(6)
            });
            this.Update(new OrderTotalsCalculated { Total = totals.Total, Lines = totals.Lines != null ? totals.Lines.ToArray() : null, IsFreeOfCharge = totals.Total == 0m });
        }
Exemple #11
0
        /// <summary>
        /// Updates the order with the specified items.
        /// </summary>
        /// <remarks>
        /// The total is now calculated at this time. This was a change done in the V3 version of the system to optimize 
        /// the UI workflow. 
        /// See <see cref="http://go.microsoft.com/fwlink/p/?LinkID=258557"> Journey chapter 7</see> for more information on 
        /// the optimization and migration to V3.
        /// </remarks>
        /// <param name="items">The desired seats to register to.</param>
        /// <param name="pricingService">Service that calculates the pricing.</param>
        public void UpdateSeats(IEnumerable<OrderItem> items, IPricingService pricingService)
        {
            var all = ConvertItems(items);
            var totals = pricingService.CalculateTotal(this.conferenceId, all.AsReadOnly());

            this.Update(new OrderUpdated { Seats = all });
            this.Update(new OrderTotalsCalculated { Total = totals.Total, Lines = totals.Lines != null ? totals.Lines.ToArray() : null, IsFreeOfCharge = totals.Total == 0m });
        }