annotate SilverlightGlimpse/SilverlightValidation/ViewModels/UserListViewModel.cs @ 71:96e6fbd70f49

Latest version
author Steven Hollidge <stevenhollidge@hotmail.com>
date Mon, 23 Apr 2012 14:54:24 +0100
parents a0bcd783e612
children
rev   line source
71
96e6fbd70f49 Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 69
diff changeset
1 using System.Collections.Generic;
96e6fbd70f49 Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 69
diff changeset
2 using System.Collections.ObjectModel;
69
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
3 using System.Windows.Input;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
4 using SilverlightValidation.Commands;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
5 using SilverlightValidation.Models;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
6 using SilverlightValidation.Validators;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
7 using SilverlightValidation.Views;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
8 using GalaSoft.MvvmLight.Messaging;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
9 using SilverlightValidation.Messages;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
10
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
11 namespace SilverlightValidation.ViewModels
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
12 {
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
13 public class UserListViewModel
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
14 {
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
15 UserView window;
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
16
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
17 public UserListViewModel(IList<UserModel> models, UserModelValidator validator)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
18 {
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
19 Data = new ObservableCollection<UserViewModel>();
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
20
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
21 foreach (var model in models)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
22 Data.Add(new UserViewModel(model, validator));
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
24 AddCommand = new RelayCommand(AddCommandExecute);
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
25 DeleteCommand = new RelayCommand(DeleteCommandExecute);
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
26
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
27 Messenger.Default.Register<UserViewResponseMessage>(this, UserViewResponseMessageReceived);
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
28 }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
29
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
30 private void UserViewResponseMessageReceived(UserViewResponseMessage userViewResponseMessage)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
31 {
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
32 if (userViewResponseMessage.UserViewModel != null)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
33 Data.Add(userViewResponseMessage.UserViewModel);
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
34 window.Close();
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
35 }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
36
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
37 #region Properties
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
38
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
39 public ObservableCollection<UserViewModel> Data { get; set; }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
40
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
41 public UserViewModel SelectedItem { get; set; }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
42
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
43 #endregion
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
44
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
45 #region Commands
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
46
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
47 public ICommand AddCommand { get; set; }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
48 public ICommand DeleteCommand { get; set; }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
49
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
50 private void AddCommandExecute(object obj)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
51 {
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
52 window = new UserView();
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
53 window.Show();
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
54 }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
55
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
56 private void DeleteCommandExecute(object obj)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
57 {
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
58 if (SelectedItem!=null)
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
59 Data.Remove(SelectedItem);
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
60 }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
61
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
62 #endregion
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
63 }
a0bcd783e612 Latest work
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
64 }