Example #1
0
        private void UpdateGameDb()
        {
            var gameService = new GameService.GameService(_executingDirectory);

            var gameIds = FolderUtils.GetGameIds(_executingDirectory);

            using (var db = new GameDbContext(_executingDirectory))
            {
                foreach (var existingGame in db.Games)
                {
                    db.Remove(existingGame);
                }

                foreach (var existingDisc in db.Discs)
                {
                    db.Remove(existingDisc);
                }

                db.SaveChanges();

                foreach (var id in gameIds)
                {
                    var gameInfo = gameService.GetGameInfo(id);

                    var game = new Game()
                    {
                        Id        = id,
                        Title     = gameInfo.Title,
                        Publisher = gameInfo.Publisher,
                        Year      = gameInfo.Year,
                        Players   = gameInfo.Players
                    };

                    var i = 1;

                    foreach (var discId in gameInfo.DiscIds)
                    {
                        var disc = new Disc()
                        {
                            GameId       = id,
                            DiscNumber   = i,
                            DiscBasename = discId
                        };

                        i++;

                        db.Add(disc);
                    }

                    db.Add(game);
                }

                db.SaveChanges();
            }
        }
Example #2
0
        private async Task <(bool IsSuccess, string ErrorMessage)> DeleteGameIfFinished(string gameId, string requestingPlayerId)
        {
            var gameState = await _dbContext.GameStates
                            .FirstOrDefaultAsync(x => x.GameId == gameId);

            if (gameState == null)
            {
                return(false, "GameId not found");
            }

            if (gameState.PlayerId != requestingPlayerId)
            {
                return(false, "Only dealer can initiate this request");
            }

            if (!gameState.IsFinished)
            {
                return(false, "Game is in progress");
            }

            _dbContext.Remove(gameState);
            await _dbContext.SaveChangesAsync();

            return(true, string.Empty);
        }
Example #3
0
        private async Task <GameSession> StopGameHandler(GameRoom room, GamerAccount callerAccount)
        {
            var session =
                await _dataContext.GameSessions.FirstOrDefaultAsync(s =>
                                                                    s.RoomId == room.Id && s.State != GameSessionStates.GameOver);

            if (session == null)
            {
                throw new Exception("Игры нет, сначала создай ее, а потом закрывай)");
            }

            if (session.State == GameSessionStates.Playing)
            {
                throw new Exception("Нельзя так! Народ играет!");
            }

            if (session.CreatedByGamerAccountId != callerAccount.Id)
            {
                throw new Exception("Игру может удалить только ее создатель!");
            }

            _dataContext.Remove(session);
            await _dataContext.SaveChangesAsync();

            return(session);
        }
        public override async Task <IdentityResult> DeleteAsync(UserModel user)
        {
            using var dbContext = new GameDbContext(_dbContextOptions);
            var current = await dbContext.Set <UserModel>().FirstOrDefaultAsync(x => x.Id == user.Id);

            dbContext.Remove(current);
            await dbContext.SaveChangesAsync();

            if (await dbContext.Set <UserModel>().FirstOrDefaultAsync(x => x.Id == user.Id) == null)
            {
                return(IdentityResult.Success);
            }
            else
            {
                return(IdentityResult.Failed());
            }
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var comment = _context.Comment.Find(id);

            if (comment == null)
            {
                return(NotFound());
            }

            _context.Remove(comment);
            _context.SaveChanges();

            return(Ok("Removed"));
        }