Exemple #1
0
        public bool StoreUserScore(UserScoreParam param, ref UserRankInfo rankInfo)
        {
            using (var connection = new SQLiteConnection(ConnectionString))// 「DataSource=:memory:」にするとオンメモリのDBとして動作
            {
                // データベースに接続
                connection.Open();

                using (var context = new DataContext(connection))
                {
                    User user = User.Find(context, param.Sereal);

                    if (user == null)
                    {
                        connection.Close();
                        return(false);
                    }
                    UserScore score = new UserScore(user);
                    score.Point = param.Point;
                    bool ret = score.Commit(connection);

                    if (rankInfo != null)
                    {
                        rankInfo.UserId = score.UserId;
                        rankInfo.Name   = user.Name;
                        rankInfo.Point  = score.Point;
                        rankInfo.Rank   = score.Rank(context);
                    }

                    connection.Close();
                    return(ret);
                }
            }
        }
Exemple #2
0
        public UserRankInfo[] GetRanking(RankingRequest request)
        {
            using (var connection = new SQLiteConnection(ConnectionString))// 「DataSource=:memory:」にするとオンメモリのDBとして動作
            {
                // データベースに接続
                connection.Open();

                using (var context = new DataContext(connection))
                {
                    User target = (request.Sereal != 0)? User.Find(context, request.Sereal): null;

                    var data = UserScore.Rank(context, request.Skip, request.Take, target);


                    UserRankInfo[] ret = new UserRankInfo[data.Length];

//                    foreach (var score in data)
                    for (int i = 0; i < data.Length; i++)
                    {
                        var score = data[i];

                        UserRankInfo rankInfo = new UserRankInfo();
                        rankInfo.Point = score.Point;
                        rankInfo.Rank  = request.Skip + i;

                        User user = User.FindByUserId(context, score.UserId);
                        rankInfo.UserId = score.UserId;
                        rankInfo.Name   = user.Name;

                        ret[i] = rankInfo;
                    }
                    connection.Close();
                    return(ret);
                }
            }
        }