public List <string> PostWebTicketToDb(WebTicket webTicket, string userId) { var response = new List <string>(); webTicket.UserBalance = GetUserWalletBalance(userId).Amount; webTicket.User = _context.ApplicationUsers.FirstOrDefault(x => x.Id == userId); var result = _ticketValidator.Validate(webTicket); if (!result.IsValid) { foreach (var error in result.Errors) { response.Add(error.ToString()); } return(response); } else { try { var ticket = new Ticket { TicketCode = Service.GenerateTicketCode(), Stake = webTicket.Stake, PossibleReturn = webTicket.PossibleReturn, StakeWithManipulationCosts = webTicket.StakeWithManipulationCosts, TicketMatches = webTicket.TicketMatches.ToList(), TotalMatchesCoefficient = webTicket.TotalMatchesCoefficient, ApplicationUserId = userId }; _context.Tickets.Add(ticket); foreach (var match in webTicket.TicketMatches) { _context.TicketMatches.Add(match); } _context.SaveChanges(); var withdrawTransaction = new WebWallet { Amount = -webTicket.Stake, }; MakeTransaction(withdrawTransaction, userId); return(response); } catch (Exception ex) { throw ex; } } }
public void MakeTransaction(WebWallet webWalletDeposit, string userId) { try { var transaction = new Transaction { Amount = webWalletDeposit.Amount, TransactionDate = DateTime.Now, ApplicationUserId = userId }; _context.Transactions.Add(transaction); _context.SaveChanges(); } catch (Exception ex) { throw ex; } }
public IActionResult PostDepositToWallet(WebWallet webWalletDeposit, string userId) { _webBetQueries.MakeTransaction(webWalletDeposit, userId); return(Ok()); }