public void EditFood(FoodViewModel food) { var query = db.Food.Where(x => x.id == food.id).First(); query.name = food.name; query.calories = food.calories; query.categoryId = food.categoryId; db.SaveChanges(); }
public ActionResult EditFood(FoodViewModel food) { if (ModelState.IsValid) { foodModel.EditFood(food); } ViewBag.Categories = categoryModel.Categories(); return RedirectToAction("Index", "Food"); }
public void AddFood(FoodViewModel food) { Food newFood = new Food() { name = food.name, calories = food.calories, categoryId = food.categoryId }; db.Food.Add(newFood); db.SaveChanges(); }