private void SetPointsVote(ref CountryListItemViewModel pointsVote, int numPoints, CountryListItemViewModel value) { var oldValue = pointsVote; Set(ref pointsVote, value); if (oldValue == null) { Messenger.Default.Send(new UpdateCountriesToGivePointsToMessage(), this.Id); } if (isReadyForLateVotes) { Messenger.Default.Send(new LateVoteCastMessage(Id, value.Id, numPoints)); } }
private void InsertCountryOrdered(CountryListItemViewModel newCountry) { bool isInserted = false; foreach (var country in Countries) { if (string.Compare(country.Name, newCountry.Name) == 1) { Countries.Insert(Countries.IndexOf(country), newCountry); isInserted = true; break; } } if (!isInserted) { Countries.Add(newCountry); } }
public CountryResultsControlViewModel(Country country, IDataService dataService) { this.dataService = dataService; this.country = country; Id = country.Id; Name = country.Name; IsInQueue = true; ClickCommand = new RelayCommand(() => IsSelected = true); FlagImage = country.FlagImage?.ToBitmapImage(); var votes = dataService.GetIssuedVotes(country.Id); var eightPoints = votes.FirstOrDefault(v => v.NumPoints == 8); var tenPoints = votes.FirstOrDefault(v => v.NumPoints == 10); var twelvePoints = votes.FirstOrDefault(v => v.NumPoints == 12); OnUpdateCountriesToGivePointsTo(null); EightPointsVote = eightPoints != null?CountriesToGiveEightPointsTo.First(c => c.Id == eightPoints.ToCountryId) : null; TenPointsVote = tenPoints != null?CountriesToGiveTenPointsTo.First(c => c.Id == tenPoints.ToCountryId) : null; TwelvePointsVote = twelvePoints != null?CountriesToGiveTwelvePointsTo.First(c => c.Id == twelvePoints.ToCountryId) : null; Messenger.Default.Register <ReadyForLateVotesMessage>(this, (message) => this.isReadyForLateVotes = true); Messenger.Default.Register <UpdateCountriesToGivePointsToMessage>(this, Id, OnUpdateCountriesToGivePointsTo); Messenger.Default.Register <VoteCastMessage>(this, (message) => { if (message.CountryId == Id) { OnUpdateCountriesToGivePointsTo(null); EightPointsVote = eightPoints != null ? CountriesToGiveEightPointsTo.First(c => c.Id == eightPoints.ToCountryId) : null; TenPointsVote = tenPoints != null ? CountriesToGiveTenPointsTo.First(c => c.Id == tenPoints.ToCountryId) : null; TwelvePointsVote = twelvePoints != null ? CountriesToGiveTwelvePointsTo.First(c => c.Id == twelvePoints.ToCountryId) : null; } }); }