Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated to 4.2

...

Code Block
AddPerson = new CommandTaskCommand(OnAddPersonExecuteOnAddPersonExecuteAsync);
EditPerson = new CommandTaskCommand(OnEditPersonExecuteOnEditPersonExecuteAsync, OnEditPersonCanExecute);
RemovePerson = new CommandTaskCommand(OnRemovePersonExecuteOnRemovePersonExecuteAsync, OnRemovePersonCanExecute);

...

Code Block
 /// <summary>
/// Gets the AddPerson command.
/// </summary>
public CommandTaskCommand AddPerson { get; private set; }

/// <summary>
/// Method to invoke when the AddPerson command is executed.
/// </summary>
private async voidTask OnAddPersonExecuteOnAddPersonExecuteAsync()
{
    var person = new Person();
    person.LastName = FamilyName;
    // Note that we use the type factory here because it will automatically take care of any dependencies
    // that the PersonViewModel will add in the future
    var typeFactory = this.GetTypeFactory();
    var personViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion<PersonViewModel>(person);
    if (await _uiVisualizerService.ShowDialogAsync(personViewModel) ?? false)
    {
        Persons.Add(person);
    }
}

/// <summary>
/// Gets the EditPerson command.
/// </summary>
public CommandTaskCommand EditPerson { get; private set; }

/// <summary>
/// Method to check whether the EditPerson command can be executed.
/// </summary>
/// <returns><c>true</c> if the command can be executed; otherwise <c>false</c></returns>
private bool OnEditPersonCanExecute()
{
    return SelectedPerson != null;
}

/// <summary>
/// Method to invoke when the EditPerson command is executed.
/// </summary>
private async voidTask OnEditPersonExecuteOnEditPersonExecuteAsync()
{
    // Note that we use the type factory here because it will automatically take care of any dependencies
    // that the PersonViewModel will add in the future
    var typeFactory = this.GetTypeFactory();
    var personViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion<PersonViewModel>(SelectedPerson);
    await _uiVisualizerService.ShowDialogAsync(personViewModel);
}

/// <summary>
/// Gets the RemovePerson command.
/// </summary>
public CommandTaskCommand RemovePerson { get; private set; }

/// <summary>
/// Method to check whether the RemovePerson command can be executed.
/// </summary>
/// <returns><c>true</c> if the command can be executed; otherwise <c>false</c></returns>
private bool OnRemovePersonCanExecute()
{
    return SelectedPerson != null;
}

/// <summary>
/// Method to invoke when the RemovePerson command is executed.
/// </summary>
private async voidTask OnRemovePersonExecuteOnRemovePersonExecuteAsync()
{
    if (await _messageService.ShowShowAsync(string.Format("Are you sure you want to delete the person '{0}'?", SelectedPerson), 
        "Are you sure?", MessageButton.YesNo, MessageImage.Question) == MessageResult.Yes)
    {
        Persons.Remove(SelectedPerson);
        SelectedPerson = null;
    }
}

...

Code Block
AddFamily = new TaskCommand Command(OnAddFamilyExecuteOnAddFamilyExecuteAsync);
EditFamily = new CommandTaskCommand (OnEditFamilyExecuteOnEditFamilyExecuteAsync, OnEditFamilyCanExecute);
RemoveFamily = new TaskCommand Command(OnRemoveFamilyExecuteOnRemoveFamilyExecuteAsync, OnRemoveFamilyCanExecute);

...

Code Block
/// <summary>
/// Gets the AddFamily command.
/// </summary>
public CommandTaskCommand AddFamily { get; private set; }

/// <summary>
/// Method to invoke when the AddFamily command is executed.
/// </summary>
private async voidTask OnAddFamilyExecuteOnAddFamilyExecuteAsync()
{
    var family = new Family();
    // Note that we use the type factory here because it will automatically take care of any dependencies
    // that the FamilyWindowViewModel will add in the future
    var typeFactory = this.GetTypeFactory();
    var familyWindowViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion<FamilyWindowViewModel>(family);
    if (await _uiVisualizerService.ShowDialogShowDialogAsync(familyWindowViewModel) ?? false)
    {
        Families.Add(family);
    }
}

/// <summary>
/// Gets the EditFamily command.
/// </summary>
public CommandTaskCommand EditFamily { get; private set; }

/// <summary>
/// Method to check whether the EditFamily command can be executed.
/// </summary>
/// <returns><c>true</c> if the command can be executed; otherwise <c>false</c></returns>
private bool OnEditFamilyCanExecute()
{
    return SelectedFamily != null;
}

/// <summary>
/// Method to invoke when the EditFamily command is executed.
/// </summary>
private async voidTask OnEditFamilyExecuteOnEditFamilyExecuteAsync()
{
    // Note that we use the type factory here because it will automatically take care of any dependencies
    // that the PersonViewModel will add in the future
    var typeFactory = this.GetTypeFactory();
    var familyWindowViewModel = typeFactory.CreateInstanceWithParametersAndAutoCompletion<FamilyWindowViewModel>(SelectedFamily);
    await _uiVisualizerService.ShowDialogAsync(familyWindowViewModel);
}

/// <summary>
/// Gets the RemoveFamily command.
/// </summary>
public CommandTaskCommand RemoveFamily { get; private set; }

/// <summary>
/// Method to check whether the RemoveFamily command can be executed.
/// </summary>
/// <returns><c>true</c> if the command can be executed; otherwise <c>false</c></returns>
private bool OnRemoveFamilyCanExecute()
{
    return SelectedFamily != null;
}

/// <summary>
/// Method to invoke when the RemoveFamily command is executed.
/// </summary>
private async voidTask OnRemoveFamilyExecuteOnRemoveFamilyExecuteAsync()
{
    if (await _messageService.ShowShowAsync(string.Format("Are you sure you want to delete the family '{0}'?", SelectedFamily),
        "Are you sure?", MessageButton.YesNo, MessageImage.Question) == MessageResult.Yes)
    {
        Families.Remove(SelectedFamily);
        SelectedFamily = null;
    }
}

...