Esempio n. 1
0
        public void AddTicketPurchaseTest()
        {
            var ticketPurchaseModel = new TicketPurchaseModel
            {
                PurchaseDate     = DateTime.Now,
                TicketPurchaseId = 12,
                CustomerId       = 6,
                PurchaseTotal    = 5
            };

            var result = (_tenantRepository.AddTicketPurchase(ticketPurchaseModel, _tenantId)).Result;

            Assert.IsNotNull(result);
            Assert.AreEqual(_numberOfTicketPurchases, 1);
            Assert.AreEqual(12, result);
        }
        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 }));
        }
Esempio n. 3
0
        public async Task <ActionResult> PurchaseTickets(string tenant, string eventId, string customerId, string ticketPrice, string ticketCount, string sectionId)
        {
            try
            {
                bool purchaseResult  = false;
                int  numberOfTickets = Convert.ToInt32(ticketCount);

                if (string.IsNullOrEmpty(eventId) || string.IsNullOrEmpty(customerId) || string.IsNullOrEmpty(ticketPrice) || string.IsNullOrEmpty(ticketCount))
                {
                    var message = _localizer["Enter quantity"];
                    DisplayMessage(message, "Confirmation");
                    return(RedirectToAction("Index", "Events", new { tenant }));
                }

                var ticketPurchaseModel = new TicketPurchaseModel
                {
                    CustomerId    = Convert.ToInt32(customerId),
                    PurchaseTotal = Convert.ToDecimal(ticketPrice)
                };

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

                    var latestPurchaseTicketId = await _tenantRepository.GetNumberOfTicketPurchases(tenantDetails.TenantId);

                    ticketPurchaseModel.TicketPurchaseId = latestPurchaseTicketId + 1;

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

                    var ticketModel = new TicketModel
                    {
                        SectionId        = Convert.ToInt32(sectionId),
                        EventId          = Convert.ToInt32(eventId),
                        TicketPurchaseId = purchaseTicketId
                    };

                    Random rnd = new Random();
                    for (var i = 0; i < numberOfTickets; i++)
                    {
                        Random rnd2 = new Random(5000);
                        ticketModel.RowNumber  = rnd.Next(0, 100000);
                        ticketModel.SeatNumber = rnd2.Next(0, 100000);
                        purchaseResult         = await _tenantRepository.AddTicket(ticketModel, tenantDetails.TenantId);
                    }

                    if (purchaseResult)
                    {
                        var successMessage = _localizer[$"You have successfully purchased {ticketCount} ticket(s)."];
                        DisplayMessage(successMessage, "Confirmation");
                    }
                    else
                    {
                        var failureMessage = _localizer["Failed to purchase tickets."];
                        DisplayMessage(failureMessage, "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(RedirectToAction("Index", "Events", new { tenant }));
        }