Exemplo n.º 1
0
        public async Task <BingoNumbers> Add(BingoNumbers b)
        {
            _context.BingoNumbers.Add(b);
            await _context.SaveChangesAsync();

            return(b);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutBingo(long id, BingoNumbers bingo)
        {
            if (id != bingo.Id)
            {
                return(BadRequest());
            }

            _context.Entry(bingo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                //Send to hub
                SendNumberbingo(bingo);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!numberExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <ActionResult <BingoNumbers> > PostBingoNumbers(BingoNumbers b)
        {
            _context.BingoNumbers.Add(b);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetBingoNumbers", new { id = b.Id }, b));
        }
Exemplo n.º 4
0
        public IActionResult SendNumberbingo(BingoNumbers bingo)
        {
            string b = Newtonsoft.Json.JsonConvert.SerializeObject(bingo);

            _hubContext.Clients.All.SendAsync("SendBingoNumber", b);
            return(Ok(new { resp = "Send number" }));
        }
Exemplo n.º 5
0
        public async Task <BingoNumbers> Update(long id, BingoNumbers b)
        {
            b.Id = id;
            var entry = _context.BingoNumbers.First(e => e.Id == b.Id);

            _context.Entry(entry).CurrentValues.SetValues(b);
            await _context.SaveChangesAsync();

            // var updated = (_context.BingoNumbers.Update(b)).Entity;
            // if (updated == null)
            // {
            //     return null;
            // }

            //   await _context.SaveChangesAsync();
            return(entry);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <BingoNumbers> > GetNumber(long roomsId, long number)
        {
            var cards = await _context.BingoNumbers.ToListAsync();

            var bingo = new BingoNumbers();

            foreach (var cr in cards.Where(e => e.RoomsId == roomsId && e.number == number))
            {
                bingo.Id      = cr.Id;
                bingo.number  = cr.number;
                bingo.RoomsId = cr.RoomsId;
            }
            if (bingo == null)
            {
                return(NotFound());
            }
            return(Ok(bingo));
        }
Exemplo n.º 7
0
        public void TryMarkNumber(int number)
        {
            var firstOrDefault = BingoNumbers.FirstOrDefault(b => b.Number == number, new BingoNumber(-1));

            firstOrDefault.Marked = true;
        }