Skip to content

Instantly share code, notes, and snippets.

@dmitry-osin
Created July 8, 2015 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry-osin/c3dc126519e06324751f to your computer and use it in GitHub Desktop.
Save dmitry-osin/c3dc126519e06324751f to your computer and use it in GitHub Desktop.
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