public async Task <IActionResult> Tickets(TicketViewModel model) { ViewData["Message"] = "Add a ticket!"; var user = await userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{userManager.GetUserId(User)}'."); } var ticketPrice = await blockchainRepository.GetTicketPrice(model.EventId); var res = await blockchainRepository.BuyTicket(model.EventId, ticketPrice, model.Wif); ViewData["Message"] = res; string owner = await blockchainRepository.GetAddress(model.Wif); model.Tickets = eventRepository.FindTicketByOwnerId(owner); bool addedToDb = false; var ticketId = await blockchainRepository.GetTicketCount(); if (res != "smth failed" && ticketPrice != 0) { Ticket t = new Ticket { TicketId = ++ticketId, EventId = model.EventId, Owner = owner, Price = ticketPrice }; addedToDb = eventRepository.AddTicket(t); } if (res != "smth failed") { model.Link = "https://testnet.qtum.info/tx/" + res; } ViewData["Message"] = "Transaction ID:" + res; if (addedToDb) { ViewData["DbAddresult"] = "Added to DB"; } else { ViewData["DbAddresult"] = "Failed to add to DB"; } model.Tickets = eventRepository.FindTicketByOwnerId(owner); return(View(model)); }