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