annotate SilverlightValidation/SilverlightValidation.PL/ViewModels/UserListViewModel.cs @ 98:d0c2cac12376

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