annotate SilverlightValidation/SilverlightValidation/ViewModels/UserListViewModel.cs @ 60:fc62c971a117

upload to blog
author Steven Hollidge <stevenhollidge@hotmail.com>
date Sat, 21 Apr 2012 21:19:39 +0100
parents 3591c26bd63e
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;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
3 using System.Windows.Input;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
4 using SilverlightValidation.Commands;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
5 using SilverlightValidation.Models;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
6 using SilverlightValidation.Validators;
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
7 using SilverlightValidation.Views;
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 {
60
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
15 UserView window;
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
16
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
17 public UserListViewModel(IList<UserModel> models, UserModelValidator validator)
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
18 {
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
19 Data = new ObservableCollection<UserViewModel>();
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
20
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
21 foreach (var model in models)
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
22 Data.Add(new UserViewModel(model, validator));
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
24 AddCommand = new RelayCommand(AddCommandExecute);
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
25 DeleteCommand = new RelayCommand(DeleteCommandExecute);
60
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
26
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
27 Messenger.Default.Register<UserViewResponseMessage>(this, UserViewResponseMessageReceived);
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
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
30 private void UserViewResponseMessageReceived(UserViewResponseMessage userViewResponseMessage)
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 if (userViewResponseMessage.UserViewModel != null)
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
33 Data.Add(userViewResponseMessage.UserViewModel);
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
34 window.Close();
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
35 }
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
36
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
37 #region Properties
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
38
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
39 public ObservableCollection<UserViewModel> Data { get; set; }
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 UserViewModel SelectedItem { 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 #endregion
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 #region Commands
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 public ICommand AddCommand { get; set; }
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
48 public ICommand DeleteCommand { get; set; }
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
49
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
50 private void AddCommandExecute(object obj)
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
51 {
60
fc62c971a117 upload to blog
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 59
diff changeset
52 window = new UserView();
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
53 window.Show();
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
54 }
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
55
59
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
56 private void DeleteCommandExecute(object obj)
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
57 {
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
58 if (SelectedItem!=null)
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
59 Data.Remove(SelectedItem);
3591c26bd63e MVVMLight added
Steven Hollidge <stevenhollidge@hotmail.com>
parents: 58
diff changeset
60 }
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 #endregion
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
63 }
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
64 }