in App/src/Events-TenantUserApp/Controllers/FindSeatsController.cs [121:160]
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 });
}