public void ClearTeams() { lock (UndoActions) { UndoActions.Add( new ChGKCommand { OnApply = () => { _service.RemoveAllTeams(); _gaService.ReportEvent(GACategory.DealWithTeams, GAAction.Click, "all teams removed"); }, OnUndo = () => { LoadTeams(); }, }); Teams = new List <TeamViewModel>(); } UndoBarMetaData = new UndoBarMetadata { Text = StringResources.TeamsRemoved }; }
void RemoveTeam(object parameter) { lock (UndoActions) { var position = ((int[])parameter)[0]; var teamToDelete = Teams[position]; UndoActions.Add( new ChGKCommand { OnApply = () => { _service.RemoveTeam(teamToDelete.ID); _gaService.ReportEvent(GACategory.DealWithTeams, GAAction.Click, "team removed"); }, OnUndo = () => { Teams.Insert(position, teamToDelete); Teams = Teams.Where(_ => true).ToList(); }, }); Teams = Teams.Where((m, i) => i != position).ToList(); } UndoBarMetaData = new UndoBarMetadata { Text = StringResources.TeamRemoved }; }
public void ClearResults() { lock (UndoActions) { var oldTeamScores = Teams.Select(team => team.Score).ToList(); UndoActions.Add( new ChGKCommand { OnApply = () => { _service.CleanResults(); _gaService.ReportEvent(GACategory.DealWithTeams, GAAction.Click, "results cleaned"); }, OnUndo = () => { Teams = Teams.Where((team, i) => { try { team.Score = oldTeamScores[i]; } catch { }; return(true); }).ToList(); }, }); Teams = Teams.Where(team => { team.Score = 0; return(true); }).ToList(); } UndoBarMetaData = new UndoBarMetadata { Text = StringResources.ScoreRemoved }; }