private void SaveRecipeComponent(object recipeComponentInstance) { RecipeComponentViewModel recipeComponentViewModel = recipeComponentInstance as RecipeComponentViewModel; if (recipeComponentViewModel.RecipeComponent != null) { if (!recipeComponentViewModel.IsValid) { Application.Current.MainPage.DisplayAlert("Предупреждение", "Выберите компонент", "Ok"); return; } using (AppDbContext db = App.GetContext()) { if (recipeComponentViewModel.RecipeComponent.RecipeComponentId == 0) { recipeComponentViewModel.RecipeComponent.Order = RecipeComponents.Count + 1; db.Entry(recipeComponentViewModel.RecipeComponent).State = EntityState.Added; } else { db.RecipeComponents.Update(recipeComponentViewModel.RecipeComponent); } db.SaveChanges(); } } Back(); }
public GroupedComponentsViewModel(bool isEditMode, RecipeViewModel recipeViewModel, RecipeComponentViewModel recipeComponentViewModel) { IsEditMode = isEditMode; RecipeViewModel = recipeViewModel; RecipeComponentViewModel = recipeComponentViewModel; LoadManufacturers(); CreateManufacturerCommand = new Command(CreateManufacturer); DeleteManufacturerCommand = new Command(DeleteManufacturer); SaveManufacturerCommand = new Command(SaveManufacturer); }
private void DeleteRecipeComponent(object recipeComponentInstance) { RecipeComponentViewModel recipeComponentViewModel = recipeComponentInstance as RecipeComponentViewModel; if (recipeComponentViewModel.RecipeComponent != null && recipeComponentViewModel.RecipeComponent.RecipeComponentId != 0) { using (AppDbContext db = App.GetContext()) { db.RecipeComponents.Remove(recipeComponentViewModel.RecipeComponent); db.SaveChanges(); } ReorderComponents(recipeComponentViewModel.RecipeComponent.Order); } Back(); }
public ComponentsViewModel(Manufacturer manufacturer, bool isEditMode, RecipeViewModel recipeViewModel, RecipeComponentViewModel recipeComponentViewModel) { Manufacturer = manufacturer; Title = "Производитель: " + Manufacturer.Name + "\nСписок компонентов"; CreateCommand = new Command(CreateComponent); DeleteCommand = new Command(DeleteComponent); SaveCommand = new Command(SaveComponent); BackCommand = new Command(Back); LoadFileCommand = new Command(LoadFileAsync); IsEditMode = isEditMode; RecipeViewModel = recipeViewModel; RecipeComponentViewModel = recipeComponentViewModel; }