コード例 #1
0
        public async Task<IHttpActionResult> Get(int id)
        {
            var order = await repository.RetrieveAsync(id);
            if (order == null || order.UserName != User.Identity.Name)
            {
                return NotFound();
            }

            var response = new SecureOrderApiModel
            {
                OrderID = order.OrderID,
                EnteredOn = order.EnteredOn,
                OrderStatus = order.OrderStatus.ToString(),
                OrderTotal = order.OrderTotal,
                UserName = order.UserName,
                Tickets = new List<SecureTicketSeatApiModel>()
            };

            foreach (var x in order.Tickets)
            {
                var ticket = new SecureTicketSeatApiModel
                {
                    ConfirmationNumber = x.TicketSeat.PendingPurchaseConfirmation,
                    TicketSeatID = x.TicketSeat.TicketSeatID,
                    TicketPriceID = x.TicketPriceID,
                    AgeID = x.TicketPrice.EventAgeGroupID,
                    BasePrice = x.TicketPrice.BasePrice,
                    TotalPrice = x.TicketTotalPrice,
                    EventName = x.TicketSeat.TicketArea.Event.PageContent.Heading,
                    TicketDiscountID = x.TicketDiscountID,
                    DiscountConfirmationNumber = x.TicketDiscount?.SecurityConfirmationNumber,
                    Options = new Dictionary<int, int>(),
                    IsValid = true
                };

                foreach (var y in x.TicketOptionChoices)
                {
                    ticket.Options.Add(y.TicketOptionID, y.TicketOptionChoiceID);
                }
                response.Tickets.Add(ticket);
            }

            return Ok(response);
        }
コード例 #2
0
        public async Task<IHttpActionResult> Post(SecureTicketSeatApiModel[] model)
        {
            if (model == null || model.Length == 0)
            {
                return Ok();
            }

            //Create Order
            DexCMS.Tickets.Orders.Models.Order order = new DexCMS.Tickets.Orders.Models.Order
            {
                EnteredOn = cstTime,
                OrderStatus = OrderStatus.Pending,
                OrderTicketReferences = new List<OrderTicketReference>(),
                UserName = User.Identity.Name
            };

            foreach (var item in model)
            {
                OrderTicketReference ticketRef = new OrderTicketReference
                {
                    TicketSeatID = item.TicketSeatID,
                    PendingPurchaseConfirmation = item.ConfirmationNumber,
                    EventAgeGroupID = item.AgeID,
                    TicketDiscountID = item.TicketDiscountID,
                    SecurityConfirmationNumber = item.DiscountConfirmationNumber,
                    TotalPrice = item.TotalPrice
                };

                if (item.Options != null && item.Options.Count > 0)
                {
                    ticketRef.TicketOptionChoices = new List<int>();
                    foreach (KeyValuePair<int, int> optionChoice in item.Options)
                    {
                        ticketRef.TicketOptionChoices.Add(optionChoice.Value);
                    }
                }

                order.OrderTicketReferences.Add(ticketRef);
            }

            //save
            await repository.AddAsync(order);

            if (order.OrderTotal > 0)
            {
                //Create order with paypal
                var payment = CreatePayment(order);

                var createdPayment = payment.Create(PaypalConfiguration.GetAPIContext());
                var links = createdPayment.links.GetEnumerator();
                var approvalUrl = "";
                while (links.MoveNext())
                {
                    var link = links.Current;
                    if (link.rel.ToLower().Trim().Equals("approval_url"))
                    {
                        approvalUrl = link.href;
                    }
                }

                return Ok(new
                {
                    OrderID = order.OrderID,
                    ApprovalUrl = approvalUrl
                });
            }
            else
            {
                order.Payments = new List<DexCMS.Tickets.Orders.Models.Payment>();

                order.Payments.Add(new DexCMS.Tickets.Orders.Models.Payment
                {
                    GrossPaid = 0,
                    NetPaid = 0,
                    OrderID = order.OrderID,
                    PaidOn = DateTime.Now,
                    PaymentDetails = "{\"type\":\"Automatic\"}",
                    PaymentFee = 0,
                    PaymentType = PaymentType.NoCharge
                });

                order.OrderStatus = OrderStatus.Complete;

                await repository.UpdateAsync(order, order.OrderID);

                return Ok(new { OrderID = order.OrderID });
            }
        }