public async Task <ActionResult> PurchaseTickets(string tenant, int eventId, int customerId, decimal ticketPrice, int ticketCount, int sectionId)
        {
            try
            {
                bool purchaseResult = false;

                var ticketPurchaseModel = new TicketPurchaseModel
                {
                    CustomerId    = customerId,
                    PurchaseTotal = ticketPrice
                };

                var tenantDetails = (_catalogRepository.GetTenant(tenant)).Result;
                if (tenantDetails != null)
                {
                    SetTenantConfig(tenantDetails.TenantId, tenantDetails.TenantIdInString);

                    var purchaseTicketId = await _tenantRepository.AddTicketPurchase(ticketPurchaseModel, tenantDetails.TenantId);

                    List <TicketModel> ticketsModel = BuildTicketModel(eventId, sectionId, ticketCount, purchaseTicketId);
                    purchaseResult = await _tenantRepository.AddTickets(ticketsModel, tenantDetails.TenantId);

                    if (purchaseResult)
                    {
                        DisplayMessage(_localizer[$"You have successfully purchased {ticketCount} ticket(s)."], "Confirmation");
                    }
                    else
                    {
                        DisplayMessage(_localizer["Failed to purchase tickets."], "Error");
                    }
                }
                else
                {
                    return(View("TenantError", tenant));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(0, ex, "Purchase tickets failed for tenant {tenant} and event {eventId}", tenant, eventId);
                return(View("TenantError", tenant));
            }
            return(RedirectToAction("Index", "Events", new { tenant }));
        }
Пример #2
0
        public async Task AddTicketTest()
        {
            var ticketModel = new List <TicketModel>();

            ticketModel.Add(new TicketModel
            {
                SectionId        = 2,
                EventId          = 4,
                TicketPurchaseId = 50,
                SeatNumber       = 41,
                RowNumber        = 22,
                TicketId         = 100
            });

            var result = await _tenantRepository.AddTickets(ticketModel, _tenantId);

            Assert.IsNotNull(result);
            Assert.IsTrue(result);
        }