Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,GameId,SquareId,xVall,yVal")] SquareCard squareCard)
        {
            if (id != squareCard.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(squareCard);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SquareCardExists(squareCard.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(squareCard));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Id,GameId,SquareId,xVall,yVal")] SquareCard squareCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(squareCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(squareCard));
        }
Пример #3
0
        private int GenerateRandomYScore(int gameId)
        {
            Random random = new Random();
            int    score  = 0;

            do
            {
                score = random.Next(0, 10);
                SquareCard card = _context.SquareCard
                                  .Where(s => s.GameId == gameId && s.yVal == score)
                                  .FirstOrDefault <SquareCard>();

                if (card == null)
                {
                    return(score);
                }
            }while(true);
        }
Пример #4
0
        public async Task <ActionResult> Assign(int gameId)
        {
            for (int i = 1; i <= 10; i++)
            {
                int x          = GenerateRandomXScore(gameId);
                int y          = GenerateRandomYScore(gameId);
                var squareCard = new SquareCard();

                squareCard.GameId   = gameId;
                squareCard.SquareId = i;
                squareCard.xVall    = x;
                squareCard.yVal     = y;

                _context.Add(squareCard);
                await _context.SaveChangesAsync();
            }

            string url = string.Concat("/Square/Index/", gameId);

            return(Redirect(url));
        }