private void AddMultiple()
 {
     Ingredients ??= new ObservableCollection <RecipeIngredientEdit>();
     Ingredient.Order = Ingredients.Count + 1;
     Ingredients.Add(Ingredient);
     Ingredient = new RecipeIngredientEdit();
 }
    /// <summary>
    /// Initializes a new instance of the <see cref="RecipeIngredientEditViewModel"/> class.
    /// </summary>
    /// <param name="dialogService">Dialog service dependency.</param>
    /// <param name="ingredientService">Ingredient service dependency.</param>
    /// <param name="measureUnitService">Provider for a list of measurement units.</param>
    /// <param name="ingredient">Ingredient to edit.</param>
    public RecipeIngredientEditViewModel(DialogService dialogService,
                                         CRUDService <Ingredient> ingredientService,
                                         CRUDService <MeasureUnit> measureUnitService,
                                         RecipeIngredientEdit ingredient)
        : base(dialogService)
    {
        this.dialogService     = dialogService;
        this.ingredientService = ingredientService;

        Ingredient       = ingredient;
        MeasurementUnits = measureUnitService.GetAll();

        AddMultipleCommand      = new DelegateCommand(AddMultiple, canExecute: CanOk);
        RemoveIngredientCommand = new DelegateCommand <RecipeIngredientEdit>(RemoveIngredient);
        CreateIngredientCommand = new AsyncDelegateCommand(CreateIngredientAsync);

        AllIngredients = ingredientService.GetProjected <IngredientEdit>();
    }
 private void RemoveIngredient(RecipeIngredientEdit i) => Ingredients !.Remove(i);