private void OnSelect(string dishName, IDishViewController dishViewController, IIngredientSubject ingredientSubject) { using (IDishController controller = factory.CreateDishController()) { DataControllerMessage <DishEditDTO> controllerMessage = controller.Get(dishName); if (controllerMessage.IsSuccess) { UIElement view = dishViewController.GetEditView(ingredientSubject, controllerMessage.Data); Window window = WindowFactory.CreateByContentsSize(view); window.Title = String.Format("{0} - {1}", dishName, controllerMessage.Data.CategoryName); dishViewController.DishDeleted += (s, e) => { if (dishName == e.Data) { window.Close(); } }; window.Show(); } else { MessageBox.Show(controllerMessage.Message); } } }
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); }
private void OnSelected(DishDisplayDTO dishDisplayDTO, IIngredientSubject subject) { using (IDishController controller = factory.CreateDishController()) { DataControllerMessage <DishEditDTO> controllerMessage = controller.Get(dishDisplayDTO.Name); if (controllerMessage.IsSuccess) { Edit(controllerMessage.Data, subject); } else { MessageBox.Show(controllerMessage.Message); } } }
public void Update() { Dishes.Clear(); using (IDishController controller = factory.CreateDishController()) { DataControllerMessage <IEnumerable <DishDisplayDTO> > controllerMessage = controller.GetAll(); if (controllerMessage.IsSuccess) { foreach (DishDisplayDTO dish in controllerMessage.Data) { Dishes.Add(dish); } } } }
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(); }
private void OnAdd(DishAddDTO dish, DishAddViewModel viewModel) { using (IDishController controller = factory.CreateDishController()) { ControllerMessage controllerMessage = controller.Add(dish); if (controllerMessage.IsSuccess) { viewModel.Name = String.Empty; viewModel.Price = 0; Notify(); } else { MessageBox.Show(controllerMessage.Message); } } }