public async Task <IActionResult> Create([Bind("Name,PricePerPerson,Description,Notes,Preparation")] DishComponent component) { try { if (component.Name != null && !String.IsNullOrEmpty(component.Name)) { component.Guid = Guid.NewGuid(); _db.Add(component); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (Exception e) { ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator. " + e); } ComponentData data = new ComponentData() { Component = component, Ingredients = _db.Ingredients.ToList() }; return(View(data)); }
public GameLogic(string categoryName, string correctDishName, string wrongDishName) { _current = new DishComponent(categoryName); _current.Correct = new DishComponent(correctDishName); _current.Wrong = new DishComponent(wrongDishName); _tree = _current; }
public async Task <IActionResult> Delete(long id) { DishComponent component = _db.DishComponents.First(x => x.ID == id); _db.Remove(component); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IActionResult Detail(long id) { DishComponent component = _db.DishComponents.First(x => x.ID == id); ComponentData data = new ComponentData() { Component = component, Ingredients = _db.Ingredients.ToList() }; return(View("Detail", data)); }
public IActionResult Coupling(long id) { DishComponent component = _db.DishComponents.First(x => x.ID == id); DishComponentIngredientData data = new DishComponentIngredientData() { DishComponent = component, Ingredients = _db.Ingredients.ToList() }; return(View("Coupling", data)); }
public async Task <IActionResult> Update([Bind("ID,Name,PricePerPerson,Description,Notes,Preparation")] DishComponent component) { DishComponent up = _db.DishComponents.First(x => x.ID == component.ID); up.Name = component.Name; up.Notes = component.Notes; up.Preparation = component.Preparation; up.PricePerPerson = component.PricePerPerson; up.Description = component.Description; _db.Entry(up).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public void CreateDish(DishComponent current, string categoryName, string dishName, bool answer) { var newCategory = new DishComponent(categoryName); newCategory.Correct = new DishComponent(dishName); newCategory.Wrong = current; if (answer) { Correct = newCategory; } else { Wrong = newCategory; } }
public bool Choose(bool answer) { if (_current.IsLastOption()) { if (answer) { ResetGame(); Success = true; return(true); } else { return(false); } } else { _parent = _current; _current = _current.FindDish(answer); _lastChoice = answer; } return(true); }
private void ResetGame() { _current = _tree; }