public FriendModel(Ec2SnapshotBrowser snapshotBrowser) { this.snapshotBrowser = snapshotBrowser; // TODO: For some reason this isn't always fired this.Bind(x => x.UserId, (o, e) => { if (this.validator.CheckPropertyWithoutNotifications(() => this.UserId).Length == 0) { this.snapshotBrowser.CountSnapshotsForUserId(this.UserId).ContinueWith(t => this.NumSnapshots = t.Result); } else { this.NumSnapshots = null; } }); this.ValidateWith(() => this.Name, x => !String.IsNullOrWhiteSpace(x), "Name must not be empty"); this.ValidateWith(() => this.UserId, x => x != null && Regex.Match(x, @"^\d{12}$").Success, "Bad Amazon User Id. Must be of the form xxxxxxxxxxxx"); }
public ManageFriendsViewModel(IWindowManager windowManager, Config config, Ec2Connection connection) { this.DisplayName = "Manage Friends"; this.windowManager = windowManager; this.config = config; this.snapshotBrowser = connection.CreateSnapshotBrowser(); var getUserIdTask = connection.GetUserIdAsync(); getUserIdTask.ContinueWith(t => this.OwnUserId = t.Result, TaskContinuationOptions.OnlyOnRanToCompletion); getUserIdTask.ContinueWith(t => System.Windows.MessageBox.Show("Error occurred finding user ID\n" + t.Exception.Format(), "Error occurred finding User ID", System.Windows.MessageBoxButton.OK), TaskContinuationOptions.OnlyOnFaulted); this.ShowOfficialImages = config.MainConfig.ShowOfficialImages; this.Friends = new BindableCollection <FriendModel>(config.FriendsWithoutDefaults.Select(x => new FriendModel(x, snapshotBrowser))); this.Bind(x => x.SelectedFriend, (o, e) => this.NotifyOfPropertyChange(() => this.CanEditFriend)); this.Bind(x => x.SelectedFriend, (o, e) => this.NotifyOfPropertyChange(() => this.CanDeleteFriend)); this.Bind(x => x.FriendBeingEdited, (o, e) => this.NotifyOfPropertyChange(() => this.CanAddFriend)); this.Bind(x => x.FriendBeingEdited, (o, e) => this.NotifyOfPropertyChange(() => this.CanEditFriend)); this.Bind(x => x.FriendBeingEdited, (o, e) => this.NotifyOfPropertyChange(() => this.CanSave)); }
public FriendModel(Friend friend, Ec2SnapshotBrowser snapshotBrowser) : this(snapshotBrowser) { this.Name = friend.Name; this.UserId = friend.UserId; }