Exemple #1
0
        public static async Task InsertScore(SoraDbContext ctx, DbScore score)
        {
            var so = score.ScoreOwner; // Fix for an Issue with Inserting.

            score.ScoreOwner = null;
            ctx.Add(score);

            score.ScoreOwner = so; // Restore ScoreOwner

            await ctx.SaveChangesAsync();
        }
Exemple #2
0
        public static async Task NewAchievement(SoraDbContext ctx,
                                                string name, string displayName, string desc, string icon)
        {
            await ctx.Achievements.AddAsync(new DbAchievement
            {
                Name        = name,
                Description = desc,
                DisplayName = displayName,
                IconURI     = icon,
            });

            await ctx.SaveChangesAsync();
        }
Exemple #3
0
        public static async Task <DbLeaderboard> GetLeaderboardAsync(SoraDbContext ctx, int userId)
        {
            var result = ctx.Leaderboard.Where(t => t.OwnerId == userId).Select(e => e).AsNoTracking().FirstOrDefault();

            if (result != null)
            {
                return(result);
            }

            var lb = new DbLeaderboard {
                OwnerId = userId
            };

            await ctx.Leaderboard.AddAsync(lb);

            await ctx.SaveChangesAsync();

            return(lb);
        }
Exemple #4
0
        public static async Task RemoveFriend(SoraDbContext ctx, int userId, int friendId)
        {
            ctx.RemoveRange(ctx.Friends.Where(x => x.UserId == userId && x.FriendId == friendId));

            await ctx.SaveChangesAsync();
        }
Exemple #5
0
        public static async Task AddFriend(SoraDbContext ctx, int userId, int friendId)
        {
            await ctx.Friends.AddAsync(new DbFriend { UserId = userId, FriendId = friendId });

            await ctx.SaveChangesAsync();
        }