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