public void ArrangeScoreBets(ICollection <MatchViewModel> matches, ICollection <UserDetailsViewModel> users, string currentUserId, bool isAdmin) { foreach (var match in matches) { var newScoreBets = new List <ScoreBetViewModel>(); foreach (var user in users) { var foundScoreBet = match.ScoreBets.FirstOrDefault(x => x.User == user.ShortName); if (foundScoreBet == null) { foundScoreBet = new ScoreBetViewModel() { User = user.ShortName, Score = Constants.NO_SCORE }; } var isCurrentUser = currentUserId != null && currentUserId == user.Id; var isStarted = match.Date < DateTime.Now; foundScoreBet.Hidden = !isAdmin && !isStarted && !isCurrentUser; foundScoreBet.Current = (isCurrentUser && !isStarted) || (isAdmin && foundScoreBet.Score != Constants.NO_SCORE); foundScoreBet.MatchId = match.Id; foundScoreBet.ClassName = GetScoreClass(foundScoreBet.Points); if (foundScoreBet.Points > 0) { foundScoreBet.Score += $" ({foundScoreBet.Points})"; } newScoreBets.Add(foundScoreBet); } match.ScoreBets = newScoreBets; } }
public async Task UpdateScoreBet(ScoreBetViewModel scoreBet) { ScoreBet updatedBet = await this.GetScoreBetByIdAsync(scoreBet.Id); updatedBet.ScoreHome = scoreBet.ScoreHome; updatedBet.ScoreAway = scoreBet.ScoreAway; _context.SaveChanges(); }
public async Task <ActionResult> Update(ScoreBetViewModel scoreBetViewModel) { if (!ModelState.IsValid) { return(View("Index", await _betService.GetListOfMatchesWithBetsAsync())); } await _betService.UpdateScoreBet(scoreBetViewModel); return(RedirectToAction("Index", "ScoreBets")); }
public async Task <ActionResult> Update(ScoreBetViewModel scoreBetViewModel) { var matchBegan = (await _context.ScoreBets.Where(b => b.Id == scoreBetViewModel.Id).Select(b => b.Match.Began).FirstOrDefaultAsync()); if (!ModelState.IsValid || matchBegan) { return(RedirectToAction("Index")); } await _betService.UpdateScoreBet(scoreBetViewModel); return(RedirectToAction("Index", "ScoreBets")); }