예제 #1
0
        public async Task <IActionResult> CreateContest([FromBody] CreateOrUpdateContestRequest request)
        {
            Guid.TryParse(User.FindFirst("id")?.Value, out var userId);

            var createdContest = await _contestService.CreateContestAsync(userId, request);

            if (createdContest != null)
            {
                return(Created(ApiHelper.GetResourceUri(HttpContext.Request, ApiRoutes.Contest.Get, createdContest.Id), _mapper.Map <ContestShortResponse>(createdContest)));
            }
            return(BadRequest());
        }
예제 #2
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));
        }
예제 #3
0
        public async Task <ActionResult> CreateContestAsync(ContestAddModel request)
        {
            try
            {
                var result = await _contestService.CreateContestAsync(request);

                return(Result.Ok(result));
            }
            catch (Exception ex)
            {
                return(Result.Error(ex));
            }
        }
예제 #4
0
        public async Task ConfigAsync()
        {
            var adminId = (await UserUtils.GetAdmin()).Id;
            var stuId   = (await UserUtils.GetStudent()).Id;

            var contest = new Data.Contest
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var cid = await contestService.CreateContestAsync(contest);

            Assert.AreNotEqual(0, cid);

            var problem = new Data.Problem
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var pid = await problemService.CreateProblemAsync(problem);

            Assert.AreNotEqual(0, pid);

            await contestService.UpdateContestProblemAsync(cid, new[] { pid, pid });

            var result = await problemService.QueryProblemAsync(stuId, cid);

            Assert.IsTrue(result /*.Cacheable()*/.Count(i => i.Id == pid) == 1);

            await contestService.UpdateContestProblemAsync(cid, new int[0]);

            result = await problemService.QueryProblemAsync(stuId, cid);

            Assert.IsFalse(result /*.Cacheable()*/.Any());
        }
예제 #5
0
        public async Task ConfigAsync()
        {
            var adminId = (await UserUtils.GetAdmin()).Id;
            var stuId   = (await UserUtils.GetStudent()).Id;

            var group = new Group
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var gid = await groupService.CreateGroupAsync(group);

            Assert.AreNotEqual(0, gid);

            var contest = new Contest
            {
                Name   = Guid.NewGuid().ToString(),
                UserId = adminId
            };

            var cid = await contestService.CreateContestAsync(contest);

            Assert.AreNotEqual(0, cid);

            await groupService.UpdateGroupContestAsync(gid, new[] { cid, cid });

            var result = await contestService.QueryContestAsync(stuId, gid);

            Assert.IsTrue(result.Count(i => i.Id == cid) == 1);

            await groupService.UpdateGroupContestAsync(gid, new int[0]);

            result = await contestService.QueryContestAsync(stuId, gid);

            Assert.IsFalse(result.Any());
        }