Exemplo n.º 1
0
        //
        // GET: Solution/Create/id
        public async Task <ActionResult> Create(int id, string name)
        {
            Languages userLanguage = await GetPerferedLanguage();

            var solutionCreateModel = new SolutionCreateModel {
                QuestionId = id, Name = name, Language = userLanguage
            };

            return(View(solutionCreateModel));
        }
Exemplo n.º 2
0
        public async Task <int> CreateSolution(int contestId, SolutionCreateModel model)
        {
            Solution solution = Mapper.Map <Solution>(model);

            _db.ContestSolutions.Add(new ContestSolution
            {
                ContestId = contestId,
                Solution  = solution
            });
            await _db.SaveChangesAsync();

            return(solution.Id);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Create(SolutionCreateModel model)
        {
            if (ModelState.IsValid)
            {
                var solution = Mapper.Map <Solution>(model);
                _db.Solutions.Add(solution);
                await _db.SaveChangesAsync();

                var judgeModel = await _db.Solutions
                                 .ProjectTo <SolutionPushModel>()
                                 .FirstOrDefaultAsync(x => x.Id == solution.Id);

                JudgeHub.Judge(judgeModel);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <IActionResult> Post([FromBody] SolutionCreateModel model)
        {
            var mapping = new Func <Solution, Task <Solution> >(async(entity) =>
            {
                entity.Name        = model.Name;
                entity.Description = model.Description;
                entity.Icon        = model.IconAssetId;
                if (!string.IsNullOrWhiteSpace(model.LayoutId))
                {
                    entity.LayoutId = model.LayoutId;
                }
                entity.CategoryId   = model.CategoryId;
                entity.Data         = model.Data;
                entity.IsSnapshot   = model.IsSnapshot;
                entity.SnapshotData = model.SnapshotData;
                entity.Color        = model.Color;
                return(await Task.FromResult(entity));
            });

            return(await _PostRequest(mapping));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Submit(int contestId, int questionId, SolutionCreateModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new HttpStatusCodeResult(400, String.Join("\n", ModelState.Select(x => $"{x.Key}:{x.Value}"))));
            }

            if (!await HasAccess(contestId))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!await _manager.IsContestStarted(contestId))
            {
                return(new HttpStatusCodeResult(400, "考试未开始或已结束。"));
            }

            int solutionId = await _manager.CreateSolution(contestId, model);

            await _manager.PushSolutionJudge(solutionId);

            return(new HttpStatusCodeResult(201, solutionId.ToString()));
        }