コード例 #1
0
 public bool AddUser(Account account, out string errorMessage)
 {
     errorMessage = string.Empty;
     try
     {
         var exUser = Articles.FindAllAsync(Schemas.User, Query.Property("username").IsEqualTo(account.UserName).ToString(), new[] { "__id" }).Result;
         if (exUser == null || exUser.Count == 0)
         {
             User user = new User();
             user.Set("username", account.UserName);
             user.Set("email", account.Email);
             user.Set("firstname", account.FirstName);
             user.Set("lastname", account.LastName);
             user.Set("password", account.Password);
             var profile = new Article(Schemas.Profile);
             profile.Set("total_points", "1");
             profile.Set("level", "1");
             profile.Set("max_game_limit", AppConfigurations.MaxAllowedGamesPerUser);
             var userProfile = Connection.New(Relations.UserProfile)
                 .FromNewArticle(Schemas.User, user)
                 .ToNewArticle(Schemas.Profile, profile).SaveAsync();
             userProfile.Wait();
             account.Id = user.Id;
             return true;
         }
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
         return false;
     }
     errorMessage = "User name already exist!!!";
     return false;
 }
コード例 #2
0
ファイル: GameDataProvider.cs プロジェクト: TokleMahesh/GOB
 public Game CreateGame(string userId, GameStatus status, bool isActive, List<string> tiles, List<string> gameTiles)
 {
     var user = new User(userId);
     var game = new Article(Schemas.Game);
     game.Set("status", status.ToString());
     game.Set("tiles", string.Join(",", gameTiles));
     var conn = Connection.New(Relations.GamePlayer)
         .FromExistingArticle("player", userId)
         .ToNewArticle("game", game);
     conn.Set("ishost", true);
     conn.Set("isactive", isActive);
     conn.Set("tiles", string.Join("|", tiles));
     conn.Set("tiles_remaining", AppConfigurations.MaxTilesPerPlayer);
     conn.SaveAsync().Wait();
     return game.ToModelGame();
 }
コード例 #3
0
ファイル: GameDataProvider.cs プロジェクト: TokleMahesh/GOB
 public bool UpdatePlayerProfile(string playerId, int points, out int level, out int totalPoints)
 {
     var user = new User(playerId);
     var profileArticle = user.GetConnectedArticlesAsync(Relations.UserProfile).Result.SingleOrDefault();
     totalPoints = profileArticle.Get<int>("total_points");
     totalPoints = totalPoints + points;
     level = (totalPoints/500) + 1;
     profileArticle.Set("total_points", totalPoints);
     profileArticle.Set("level", level);
     profileArticle.SaveAsync().Wait();
     return true;
 }
コード例 #4
0
ファイル: GameDataProvider.cs プロジェクト: TokleMahesh/GOB
 public List<string> GetUserActiveGames(string userId)
 {
     var user = new User(userId);
     var findQ = BooleanOperator.Or(new[]
     {
         Query.Property("status").IsEqualTo(GameStatus.Waiting.ToString()),
         Query.Property("status").IsEqualTo(GameStatus.Started.ToString()),
         Query.Property("status").IsEqualTo(GameStatus.Invited.ToString())
     });
     var gameArticles = user.GetAllConnectedArticles(Relations.GamePlayer, findQ.ToString(), "game", new [] {"__id"});
     return gameArticles.Select( g => g.Id).ToList();
 }
コード例 #5
0
ファイル: GameDataProvider.cs プロジェクト: TokleMahesh/GOB
 public List<Game> GetPreviousGames(string userId)
 {
     List<Game> games = new List<Game>();
     var user = new User(userId);
     var findQ = BooleanOperator.Or(new[]
     {
         Query.Property("status").IsEqualTo(GameStatus.Finished.ToString()),
         Query.Property("status").IsEqualTo(GameStatus.Resigned.ToString()),
         Query.Property("status").IsEqualTo(GameStatus.Cancelled.ToString())
     });
     var gameArticles = user.GetAllConnectedArticles(Relations.GamePlayer, findQ.ToString(), "game", new[] { "__id" });
     games = GetGameInfo(gameArticles.Select(g => g.Id));
     return games;
 }
コード例 #6
0
 public UserSession(User user, string token)
 {
     this.UserToken = token;
     this.LoggedInUser = user;
 }