public AdvertisementDetailViewModel(INewspaperAdRepository adRepository) { _adRepository = adRepository; Newspapers = new ObservableCollection<NewspaperItemViewModel>(); Messenger.Default.Register<CurrentAdvertisementItemChangedMessage>(this, (message) => { if (message.ItemViewModel != null) { ItemViewModel = message.ItemViewModel; Name = ItemViewModel.Name; Text = ItemViewModel.Text; } else { Name = Text = ""; } RaisePropertyChanged(() => AllowSave); }); Messenger.Default.Register<CurrentNewspaperItemChangedMessage>(this, (message) => { _currentNewspaper = message.ItemViewModel; }); AddItemCommand = new RelayCommand<RoutedEventArgs>(AddItemCommandHandler); CancelItemCommand = new RelayCommand(CancelItemCommandHandler); SaveItemCommand = new RelayCommand(SaveItemCommandHandler); DeleteItemCommand = new RelayCommand(DeleteItemCommandHandler); LinkToCurrentPaper = new RelayCommand(LinkToCurrentPaperHandler); Messenger.Default.Send(new AdvertisementDetailViewModelReady()); }
private void AddingNewspaperItemMessageHandler(AddingNewspaperItemMessage message) { var model = new Newspaper(); var vm = new NewspaperItemViewModel(_adRepository) {Model = model}; Newspapers.Add(vm); var sortedNewspapers = Newspapers.OrderBy(n => n.Name).ToList(); Newspapers.Clear(); sortedNewspapers.ForEach(Newspapers.Add); Messenger.Default.Send(new CurrentNewspaperItemChangedMessage(vm)); }
private void SaveCommandHandler(NewspaperItemViewModel viewModel) { if (inSave) return; inSave = true; _adRepository.Save(viewModel.Model); var sortedList = Newspapers.OrderBy(n => n.Name).ToList(); Newspapers.Clear(); sortedList.ForEach(n => Newspapers.Add(n)); inSave = false; }
public RemovingNewspaperItemMessage(NewspaperItemViewModel itemViewModel) { ItemViewModel = itemViewModel; }