Mercurial > silverbladetech
diff SilverlightValidation/SilverlightValidation.PL/ViewModels/UserListViewModel.cs @ 96:188f8b366e87
Unit test project correctly setup as normal class library DLL.
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sat, 05 May 2012 13:29:56 +0100 |
parents | SilverlightValidation/SilverlightValidation/ViewModels/UserListViewModel.cs@fc62c971a117 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SilverlightValidation/SilverlightValidation.PL/ViewModels/UserListViewModel.cs Sat May 05 13:29:56 2012 +0100 @@ -0,0 +1,65 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Windows.Controls; +using System.Windows.Input; +using SilverlightValidation.Commands; +using SilverlightValidation.Models; +using SilverlightValidation.Validators; +using GalaSoft.MvvmLight.Messaging; +using SilverlightValidation.Messages; + +namespace SilverlightValidation.ViewModels +{ + public class UserListViewModel + { + private ChildWindow _window; + + public UserListViewModel(ChildWindow window, IList<UserModel> models, UserModelValidator validator) + { + _window = window; + + Data = new ObservableCollection<UserViewModel>(); + + foreach (var model in models) + Data.Add(new UserViewModel(model, validator)); + + AddCommand = new RelayCommand(AddCommandExecute); + DeleteCommand = new RelayCommand(DeleteCommandExecute); + + Messenger.Default.Register<UserViewResponseMessage>(this, UserViewResponseMessageReceived); + } + + private void UserViewResponseMessageReceived(UserViewResponseMessage userViewResponseMessage) + { + if (userViewResponseMessage.UserViewModel != null) + Data.Add(userViewResponseMessage.UserViewModel); + _window.Close(); + } + + #region Properties + + public ObservableCollection<UserViewModel> Data { get; set; } + + public UserViewModel SelectedItem { get; set; } + + #endregion + + #region Commands + + public ICommand AddCommand { get; set; } + public ICommand DeleteCommand { get; set; } + + private void AddCommandExecute(object obj) + { + _window.Show(); + } + + private void DeleteCommandExecute(object obj) + { + if (SelectedItem!=null) + Data.Remove(SelectedItem); + } + + #endregion + } +} \ No newline at end of file