public void Payout(FinishedMatch match) { List <Bet> betList = new List <Bet>(); betList = betrep.GetBetsByMatch(match); foreach (Bet bet in betList) { if (bet.Prediction == match.Result) { userservice = new UserService(); User user = new User { UserID = bet.UserID, Balance = userservice.GetBalance(bet.UserID) }; if (bet.Prediction == MatchResult.HomeTeam) { bet.Earned = bet.Amount * match.MultiplierHome; } else if (bet.Prediction == MatchResult.AwayTeam) { bet.Earned = bet.Amount * match.MultiplierAway; } else { bet.Earned = bet.Amount * match.MultiplierDraw; } bet.Result = BetResult.Won; betrep.Update(bet); userservice.AddFunds(user, bet.Earned); } else { bet.Result = BetResult.Lost; bet.Earned = 0; betrep.Update(bet); } } }
public void BetRepository_Update_UpdatesBet() { var mockDbSet = UnitTestHelper.GetMockDbSet <Bet>(GetTestBets()); var mockContext = GetMockContext(mockDbSet); var betRepo = new BetRepository(mockContext.Object); var bet = new Bet { Id = 1, BetDate = new DateTime(2020, 11, 15), LotId = 1, UserId = "1" }; betRepo.Update(bet); mockDbSet.Verify( m => m.Attach(It.Is <Bet>( l => l.Id == bet.Id && l.BetDate == bet.BetDate && l.LotId == bet.LotId)), Times.Once); }
public Bet UpdateBet(Bet existingBet) { return(BetRepository.Update(existingBet)); }