private void OnSelectionChanged() { Money sumOfWhiteList = NonPrivatePockets .Where(pocket => pocket.Labels.All(pocketLabel => LabelsWhiteList.Any(labelViewModel => pocketLabel == labelViewModel.Value))) .Sum(x => x.Amount); if (sumOfWhiteList >= _targetAmount) { EnoughSelected = true; _includePrivatePocket = false; } else if (!LabelsBlackList.Any() && sumOfWhiteList + _privatePocket.Amount >= _targetAmount) { EnoughSelected = true; _includePrivatePocket = true; } else if (!LabelsWhiteList.Any() && _privatePocket.Amount >= _targetAmount) { EnoughSelected = true; _includePrivatePocket = true; } else { EnoughSelected = false; _includePrivatePocket = false; } this.RaisePropertyChanged(nameof(LabelsWhiteList)); this.RaisePropertyChanged(nameof(LabelsBlackList)); }
public Pocket[] GetUsedPockets() { var pocketsToReturn = NonPrivatePockets.Where(x => x.Labels.All(label => LabelsWhiteList.Any(labelViewModel => labelViewModel.Value == label))).ToList(); if (_includePrivatePocket) { pocketsToReturn.Add(_privatePocket); } return(pocketsToReturn.ToArray()); }
private void OnSelectionChanged() { Money sumOfWhiteList = NonPrivatePockets .Where(pocket => pocket.Labels.All(pocketLabel => LabelsWhiteList.Any(labelViewModel => pocketLabel == labelViewModel.Value))) .Sum(x => x.Amount); _includePrivatePocket = NonPrivatePockets.Sum(x => x.Amount) < _targetAmount || (LabelsWhiteList.IsEmpty() && _privatePocket.Amount >= _targetAmount); var totalSelected = sumOfWhiteList + (_includePrivatePocket ? _privatePocket.Amount : Money.Zero); EnoughSelected = totalSelected >= _targetAmount; this.RaisePropertyChanged(nameof(LabelsWhiteList)); this.RaisePropertyChanged(nameof(LabelsBlackList)); }