コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: GameLogic.cs プロジェクト: marvinwagner/GourmetGame
        public GameLogic(string categoryName, string correctDishName, string wrongDishName)
        {
            _current         = new DishComponent(categoryName);
            _current.Correct = new DishComponent(correctDishName);
            _current.Wrong   = new DishComponent(wrongDishName);

            _tree = _current;
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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)));
        }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
ファイル: GameLogic.cs プロジェクト: marvinwagner/GourmetGame
        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);
        }
コード例 #9
0
ファイル: GameLogic.cs プロジェクト: marvinwagner/GourmetGame
 private void ResetGame()
 {
     _current = _tree;
 }