public async void AddTicketTest() { var ticketModel = new TicketModel { SectionId = 2, EventId = 4, TicketPurchaseId = 50, SeatNumber = 41, RowNumber = 22, TicketId = 100 }; var result = await _tenantRepository.AddTicket(ticketModel, _tenantId); _ticketsSold++; Assert.IsNotNull(result); Assert.IsTrue(result); }
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 })); }