Exemplo n.º 1
0
        public IActionResult DrawNumber(int id)
        {
            var game = _context.Games
                       .Include(c => c.Numbers)
                       .Single(c => c.GameNumber == id);

            var pick = Enumerable.Range(1, 99)
                       .GroupJoin(game.Numbers.Select(d => d.Number),
                                  c => c,
                                  c => c,
                                  (availableNumber, pickedNumber) => new
            {
                AvailableNumber = availableNumber,
                PickedNumber    = !pickedNumber.Any() ? null : (int?)pickedNumber.FirstOrDefault()
            })
                       .Where(c => c.PickedNumber == null)
                       .Shuffle()
                       .First()
                       .AvailableNumber;

            _context.GameNumbers.Add(new BingoGameNumber
            {
                Number     = pick,
                GameNumber = game.GameNumber
            });

            _context.SaveChanges();


            return(RedirectToAction("Show", new { id = game.GameNumber }));
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "CartelaId,CodigoTabela,Campo1,Campo2,Campo3,Campo4,Campo5,Campo6,Campo7,Campo8,Campo9,Campo10,Campo11,Campo12,Campo13,Campo14,Campo15")] Cartela cartela)
        {
            if (ModelState.IsValid)
            {
                db.Cartela.Add(cartela);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cartela));
        }
Exemplo n.º 3
0
        public IActionResult Index()
        {
            // Make the Bingo grid
            var grid = Enumerable.Range(0, 5)
                       .Select((c, i) => Enumerable.Range(0, 19).Select(d => d + i * 20 + 1).Shuffle().ToArray().Take(5).ToArray())
                       .ToArray();

            // Flatten the grid for storage in the DB
            var flattenedGrid = Enumerable.Range(0, 5).SelectMany(c => Enumerable.Range(0, 5).Select(d => grid[d][c]))
                                .ToList();

            // Remove the free space
            flattenedGrid.RemoveAt(12);

            // Generate the card
            var card = new BingoCard {
                DateCreated = DateTime.Now,
                Numbers     = flattenedGrid
                              .Select((c, i) => new BingoNumber {
                    Number = c,
                    Order  = i
                })
                              .ToArray()
            };

            _context.Cards.Add(card);
            _context.SaveChanges();

            return(RedirectToAction("Show", "Cards", new { id = card.CardNumber }));
        }