public ModifyRecipeDialog(ModifyRecipeViewModel modify) { mModify = modify; InitializeComponent(); txtName.BindText(mModify, m => m.Name); var lookUp = cboIngredients.Properties; lookUp.DataSource = modify.Ingredients; lookUp.DisplayMember = "Display"; lookUp.ShowHeader = false; lookUp.Columns.Add(new LookUpColumnInfo("Display") { Visible = true, SortOrder = ColumnSortOrder.Ascending }); cboIngredients.BindEditValue(mModify, m => m.SelectedIngredient); numNewIngredientAmount.BindValue(mModify, m => m.NewIngredientAmount); lblNewIngredientPostfix.BindText(mModify, m => m.NewIngredientPostFix); lblSelectedRecipeAmount.BindText(mModify, m => m.SelectedRecipeAmountDisplay); numNewRecipeAmount.BindValue(mModify, m => m.NewRecipeAmount); lblNewRecipePostfix.BindText(mModify, m => m.NewRecipePostFix); okCancelButtons1.Bind(modify, this); UpdateSelection(); }
private async void DoModifyRecipe() { var modify = new ModifyRecipeViewModel(this); ViewModelStack.Push(modify); if (await modify.Completed) { var recipe = CreateModifiedRecipe(modify); var viewModel = new RecipeViewModel(mRecipe.Owner, recipe); mRecipe.Owner.Items.Add(viewModel); } }
private Recipe CreateModifiedRecipe(ModifyRecipeViewModel modify) { decimal factor = 1; if (modify.ByIngredient) { factor = modify.NewIngredientAmount / modify.SelectedIngredient.Amount.Value; } else { factor = modify.NewRecipeAmount / Amount; } var ingredients = new List <IngredientReference>(); foreach (var item in mItems) { var amount = item.Amount; amount.Value *= factor; ingredients.Add(new IngredientReference { Amount = amount, IngredientID = item.IngredientID, }); } var recipe = new Recipe(); recipe.Amount = new Amount { Measurement = Measurement, Value = Amount * factor, }; recipe.ID = ID.Next; recipe.Ingredients = ingredients.ToArray(); recipe.Name = modify.Name; return(recipe); }