Example #1
0
        public UIElement GetEditView(IIngredientSubject subject, DishEditDTO dishEditDTO)
        {
            IngredientListViewModel ingredientListViewModel = new IngredientListViewModel(factory, subject);
            RecipeAddViewModel      recipeAddViewModel      = new RecipeAddViewModel(factory, this, ingredientListViewModel);

            recipeAddViewModel.MustSelectDish = false;

            DishEditViewModel viewModel = new DishEditViewModel(dishEditDTO, recipeAddViewModel);
            DishEditView      view      = new DishEditView(viewModel);

            viewModel.DishSaveRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.Update(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };
            viewModel.DishSaveRecipesRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.UpdateRecipes(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };
            viewModel.DishDeleteRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.Delete(e.Data.OldName);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                        RaiseDishDeletedEvent(e.Data.OldName);
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };

            return(view);
        }
Example #2
0
        private void Edit(DishEditDTO dishEditDTO, IIngredientSubject subject)
        {
            IngredientListViewModel ingredientListViewModel = new IngredientListViewModel(factory, subject);
            RecipeAddViewModel      recipeAddViewModel      = new RecipeAddViewModel(factory, this, ingredientListViewModel);

            recipeAddViewModel.MustSelectDish = false;

            DishEditViewModel viewModel = new DishEditViewModel(dishEditDTO, recipeAddViewModel);
            DishEditView      view      = new DishEditView(viewModel);
            Window            window    = WindowFactory.CreateByContentsSize(view);

            window.MinWidth = view.MinWidth;

            viewModel.DishSaveRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.Update(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };
            viewModel.DishSaveRecipesRequest += (s, e) =>
            {
                using (IDishController controller = factory.CreateDishController())
                {
                    ControllerMessage controllerMessage = controller.UpdateRecipes(e.Data);
                    if (controllerMessage.IsSuccess)
                    {
                        Notify();
                    }
                    else
                    {
                        MessageBox.Show(controllerMessage.Message);
                    }
                }
            };

            window.Show();
        }