Mercurial > silverbladetech
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 | 1 using System.Collections.Generic; |
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 | 4 using System.Windows.Input; |
5 using SilverlightValidation.Commands; | |
6 using SilverlightValidation.Models; | |
7 using SilverlightValidation.Validators; | |
60 | 8 using GalaSoft.MvvmLight.Messaging; |
9 using SilverlightValidation.Messages; | |
58 | 10 |
11 namespace SilverlightValidation.ViewModels | |
12 { | |
59
3591c26bd63e
MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
58
diff
changeset
|
13 public class UserListViewModel |
58 | 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 | 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 | 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 | 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 | 28 |
29 Messenger.Default.Register<UserViewResponseMessage>(this, UserViewResponseMessageReceived); | |
30 } | |
31 | |
32 private void UserViewResponseMessageReceived(UserViewResponseMessage userViewResponseMessage) | |
33 { | |
34 if (userViewResponseMessage.UserViewModel != null) | |
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 | 40 |
59
3591c26bd63e
MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
58
diff
changeset
|
41 public ObservableCollection<UserViewModel> Data { get; set; } |
58 | 42 |
59
3591c26bd63e
MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
58
diff
changeset
|
43 public UserViewModel SelectedItem { get; set; } |
58 | 44 |
59
3591c26bd63e
MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
58
diff
changeset
|
45 #endregion |
58 | 46 |
59
3591c26bd63e
MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
58
diff
changeset
|
47 #region Commands |
58 | 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 | 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 | 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 | 64 } |
65 } |