annotate SilverlightGlimpse/SilverlightValidation/ViewModels/UserListViewModel.cs @ 69:a0bcd783e612

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