コード例 #1
0
ファイル: GameRepository.cs プロジェクト: niekp/30seconds
        public async Task <Game> GetNewGame(int IdRoom, string User)
        {
            var room = await db.Room.Where(r => r.Id == IdRoom).FirstOrDefaultAsync();

            if (!(room is Room))
            {
                throw new ArgumentException("Invalid room.");
            }

            var game = new Game()
            {
                IdRoom = IdRoom,
                Room   = room,
                Start  = DateTime.Now,
                User   = User
            };

            foreach (var word in await wordRepository.GetWords(room.IdWordlist, 5))
            {
                db.Attach(word);
                game.Words.Add(word);
            }

            db.Add(game);

            await db.SaveChangesAsync();

            return(game);
        }
コード例 #2
0
        public async Task Save(GameContext db)
        {
            if (!_mailsToDelete.IsEmpty)
            {
                var idsToRemove = new List <long>();
                while (_mailsToDelete.TryPop(out var mailToDelete))
                {
                    idsToRemove.Add(mailToDelete.Id);
                }

                await db.PlayerMails.Where(x => idsToRemove.Contains(x.Id)).DeleteAsync();
            }

            foreach (var mail in _mails.Values.Where(x => x.IsDirty))
            {
                var entity = new PlayerMailEntity
                {
                    Id        = mail.Id,
                    IsMailNew = mail.IsNew
                };

                db.Attach(entity).Property(x => x.IsMailNew).IsModified = true;
                mail.SetDirtyState(false);
            }
        }
コード例 #3
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(User).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(User.user_no))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }