コード例 #1
0
 public void Save(FinishedGameDto finishedGame)
 {
     using (var db = new FifteenGameDbFirstEntities())
     {
         db.FinishedGames.Add(GameMapper.Instance.Map <FinishedGame>(finishedGame));
         db.SaveChanges();
     }
 }
コード例 #2
0
        public void RemoveCurrentGame(int userId)
        {
            using (var db = new FifteenGameDbFirstEntities())
            {
                var currentGame = db.CurrentGames.FirstOrDefault(cg => cg.UserId == userId);
                if (currentGame == null)
                {
                    return;
                }

                while (currentGame.CurrentGameCells.Any())
                {
                    db.CurrentGameCells.Remove(currentGame.CurrentGameCells.First());
                }

                db.CurrentGames.Remove(currentGame);
                db.SaveChanges();
            }
        }
コード例 #3
0
        public void SaveCurrentGameState(int userId, GameStateDto state)
        {
            using (var db = new FifteenGameDbFirstEntities())
            {
                var currentGame = db.CurrentGames.FirstOrDefault(cg => cg.UserId == userId);
                if (currentGame == null)
                {
                    currentGame = new CurrentGame
                    {
                        UserId        = userId,
                        MoveCount     = state.MoveCount,
                        GameStartTime = state.GameStartTime,
                    };

                    db.CurrentGames.Add(currentGame);
                }
                else
                {
                    currentGame.MoveCount     = state.MoveCount;
                    currentGame.GameStartTime = state.GameStartTime;
                }

                while (currentGame.CurrentGameCells.Any())
                {
                    db.CurrentGameCells.Remove(currentGame.CurrentGameCells.First());
                }

                int i = 1;
                foreach (var cell in state.State)
                {
                    currentGame.CurrentGameCells.Add(new CurrentGameCell
                    {
                        CellIndex = i,
                        CellValue = cell,
                    });

                    i++;
                }

                db.SaveChanges();
            }
        }
コード例 #4
0
ファイル: UserRepository.cs プロジェクト: wowikt/FiberTrade
        public UserDto Register(string login, string password, string userName)
        {
            using (var db = new FifteenGameDbFirstEntities())
            {
                if (db.Users.Any(u => u.Login == login))
                {
                    return(null);
                }

                var newUser = new User
                {
                    UserName = userName,
                    Login    = login,
                    Password = password,
                };

                db.Users.Add(newUser);
                db.SaveChanges();
                return(GameMapper.Instance.Map <UserDto>(newUser));
            }
        }