Exemple #1
0
        public async Task <bool> AddUserInfo(UserInfo userInfo)
        {
            userInfo.Id = daoUtils.GUID();
            await dbContext.UserInfos.AddAsync(userInfo);

            return(await dbContext.SaveChangesAsync() == 1);
        }
Exemple #2
0
        public async Task <bool> SetHighScore(string userId, int score)
        {
            var highScore = await dbContext.QuizHighScores.SingleOrDefaultAsync(q => q.UserId == userId);

            if (highScore == null)
            {
                highScore = new QuizHighScore {
                    HighScore = score, UserId = userId
                };
                await dbContext.QuizHighScores.AddAsync(highScore);

                await dbContext.SaveChangesAsync();

                return(true);
            }

            if (score <= highScore.HighScore)
            {
                return(true);
            }
            highScore.HighScore = score;
            dbContext.QuizHighScores.Update(highScore);
            await dbContext.SaveChangesAsync();

            return(true);
        }
Exemple #3
0
        public async Task <string> UploadOj(OjQuestion question, OjTestCaseTable ojTestCaseTable)
        {
            question.Id          = daoUtils.GUID();
            ojTestCaseTable.OjId = question.Id;
            await using var tx   = await dbContext.Database.BeginTransactionAsync();

            var count = await dbContext.OjQuestions.CountAsync();

            question.OrderId = count + 1;
            await dbContext.OjQuestions.AddAsync(question);

            await dbContext.SaveChangesAsync();

            ojTestCaseTable.OjId = question.Id;
            await dbContext.OjTestCaseTables.AddAsync(ojTestCaseTable);

            await dbContext.SaveChangesAsync();

            await tx.CommitAsync();

            return(question.Id);
        }
Exemple #4
0
        public async Task <bool> AddOjReview(string ojId, string userId, string review)
        {
            await dbContext.OjReviews.AddAsync(new OjReview
            {
                OjId       = ojId,
                UserId     = userId,
                Review     = review,
                CreateTime = DateTime.Now
            });

            await dbContext.SaveChangesAsync();

            return(true);
        }