Created
July 8, 2015 15:07
-
-
Save dmitry-osin/c3dc126519e06324751f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CreateEditPageViewModel : ViewModelBase | |
{ | |
public RelayCommand CancelCommand { get; set; } | |
public RelayCommand<TaskItem> SaveCommand { get; set; } | |
public TaskItem TaskItem { get; set; } | |
private IRepository<TaskItem> _repository; | |
private IPageNavigationService _navigationService; | |
private IValidationService<TaskItem> _validationService; | |
public CreateEditPageViewModel(IRepository<TaskItem> repository, IPageNavigationService navigationService, IValidationService<TaskItem> validationService) | |
{ | |
_repository = repository; | |
_navigationService = navigationService; | |
_validationService = validationService; | |
ReceiveMessage(); | |
InitCommands(); | |
} | |
private void ReceiveMessage() | |
{ | |
MessengerInstance.Register<TaskItem>(this, RegisterTaskItem); | |
} | |
private void RegisterTaskItem(TaskItem item) | |
{ | |
TaskItem = item; | |
} | |
private void InitCommands() | |
{ | |
CancelCommand = new RelayCommand(() => | |
{ | |
_navigationService.ToTasksPage(); | |
}); | |
SaveCommand = new RelayCommand<TaskItem>(item => | |
{ | |
if (_validationService.Validate(item)) | |
{ | |
TaskItem = item; | |
_navigationService.ToTasksPage(); | |
_repository.AddOrUpdate(TaskItem); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment