private async void OpenEditFoodDialogAsync(Food food) { var foodClone = food.Clone(); var dialog = _dialogs.For <FoodDialogViewModel>(DialogsIdentifier); dialog.Data.Food = FoodViewModel.FromModel(foodClone); dialog.Data.DialogTitle = "Modified food"; dialog.Data.SubmitButtonTitle = "Save"; var dialogResult = await dialog.Show(); if (dialogResult != DialogResult.Ok) { return; } foodClone = dialog.Data.Food.ToModel(); Foods.Replace(food, foodClone); _foodService.Update(foodClone, food); }
private async void OpenAddFoodDialogAsync() { var food = new Food(); food.DefaultFoodUnit.FoodUnit.Grams = FoodUnitConstants.DefaultUnitGrams; food.DefaultFoodUnit.FoodUnit.Name = FoodUnitConstants.DefaultUnitName; var dialog = _dialogs.For <FoodDialogViewModel>(DialogsIdentifier); dialog.Data.Food = FoodViewModel.FromModel(food); dialog.Data.DialogTitle = "New food"; dialog.Data.SubmitButtonTitle = "Create"; var dialogResult = await dialog.Show(); if (dialogResult != DialogResult.Ok) { return; } food = dialog.Data.Food.ToModel(); Foods.Add(food); _foodService.Create(food); }