예제 #1
0
        public async Task UpvoteContestTest()
        {
            var adminId = (await UserUtils.GetAdmin()).Id;
            var stuId   = (await UserUtils.GetStudent()).Id;

            var pubId = await contestService.CreateContestAsync(new Data.Contest
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            });

            Assert.AreNotEqual(0, pubId);

            Assert.IsTrue(await voteService.UpvoteContestAsync(stuId, pubId));
            var result = await contestService.GetContestAsync(pubId);

            Assert.AreEqual(1, result?.Upvote);

            Assert.IsFalse(await voteService.UpvoteContestAsync(stuId, pubId));
            Assert.IsFalse(await voteService.DownvoteContestAsync(stuId, pubId));
        }
예제 #2
0
        public async Task VoteContest([FromBody] ContestVoteModel model)
        {
            var userId = userManager.GetUserId(User);
            var result = model.VoteType switch
            {
                1 => await voteService.UpvoteContestAsync(userId, model.ContestId),
                2 => await voteService.DownvoteContestAsync(userId, model.ContestId),
                _ => false
            };

            if (!result)
            {
                throw new BadRequestException("评价失败");
            }
        }