private async Task MakeUserPicksAsync(long user, int week, int gamePickIndex, GameResult result) { var gamePicks = _mapper.Map <List <GamePick> >((await _gamePickService.GetByUserAndWeekAsync(user, week)).ToList()); gamePicks[gamePickIndex].Pick = result; await _gamePickService.UpdateByUserAndWeekAsync(gamePicks); }
public async Task <bool> DeleteGame(long id) { //Need to adjust user pick wagers for the week of this game var users = _userRepository.GetAll(); var game = await _gameRepository.GetById(id); // Ensure picks are created then update the wagers above the game deleted (shift down) foreach (var user in users) { var picks = (await _gamePickService.GetByUserAndWeekAsync(user.Id, game.Week)).ToList(); var wagerToDelete = picks.Find(p => p.GameId == id).Wager; var ordered = picks.OrderBy(p => p.Wager); for (int index = wagerToDelete; index < ordered.Count(); index++) { picks[index].Wager = index; } await _gamePickService.UpdateByUserAndWeekAsync(picks); } await _gameRepository.DeleteAsync(id); return(true); }
public async Task <bool> UpdateGamePicksAsync(IEnumerable <GamePick> gamePicks) { await _gamePickService.UpdateByUserAndWeekAsync(gamePicks); return(true); }