public Add_Food(MainPageViewModel obj) { a = new AddFoodViewModel(obj); InitializeComponent(); DataContext = a; }
internal async void ExecuteRunDialog(WindowArgument argument) { AddFoodViewModel model; switch (argument) { case WindowArgument.New: model = new AddFoodViewModel(); break; case WindowArgument.Edit: model = new AddFoodViewModel(_mainViewModel.SelectedFood); break; default: model = new AddFoodViewModel(); break; } //let's set up a little MVVM, cos that's what the cool kids are doing: var view = new AddFoodView() { DataContext = model }; //show the dialog var result = await DialogHost.Show(view, "RootDialog"); //check the result... Console.WriteLine("Dialog was closed, the CommandParameter used to close it was: " + (result ?? "NULL")); CalculateDialogResult(argument, result); }
public ActionResult Create([Bind(Include = "Name")] AddFoodViewModel food) { Food foods = new Food(); foods.Name = food.Name; foods.Date = DateTime.Now; if (ModelState.IsValid) { db.Food.Add(foods); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(food)); }
public IActionResult Add(AddFoodViewModel addFoodViewModel) { if (ModelState.IsValid) { NutritionPlan newNutritionPlan = context.NutritionPlans.Single(n => n.ID == addFoodViewModel.NutritionPlanID); //Add new food to context and save it Food newFood = new Food { Name = addFoodViewModel.Name, Price = addFoodViewModel.Price, NutritionPlan = newNutritionPlan }; context.Foods.Add(newFood); context.SaveChanges(); return(Redirect("/Food")); } return(View(addFoodViewModel)); }
public IActionResult Add() { AddFoodViewModel addFoodViewModel = new AddFoodViewModel(context.NutritionPlans.ToList()); return(View(addFoodViewModel)); }