Ejemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] SubmissionDTO bindingModel)
        {
            ResponseDTO dto = new ResponseDTO(ErrorModel);

            if (ModelState.IsValid)
            {
                // Massage data
                bindingModel.Email     = bindingModel.Email.Trim();
                bindingModel.FirstName = bindingModel.FirstName.Trim();
                bindingModel.LastName  = bindingModel.LastName.Trim();
                bindingModel.Comments  = bindingModel.Comments.Trim();

                // Call service to add submission
                await submissionService.AddSubmissionAsync(bindingModel.Email, bindingModel.FirstName, bindingModel.LastName, bindingModel.Comments, bindingModel.ActivityId.Value);

                // Check if error model caught anything before sending ok response.
                if (ErrorModel.Errors.Count == 0)
                {
                    return(Ok(dto));
                }
            }

            // TODO: Add field to ErrorModel to determine if 500 error should show
            return(BadRequest(dto));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddSubmissionAsync(long contestId, long problemId, [FromForm] AddSubmissionViewModel addSubmission)
        {
            var userId = _authService.GetUserIdFromRequest(Request.HttpContext.User.Claims);

            var result = await _submissionService.AddSubmissionAsync(contestId, problemId, userId, addSubmission);

            switch (result.Error)
            {
            case AddSubmissionResultType.Unauthorized:
                return(new ObjectResult(result)
                {
                    StatusCode = StatusCodes.Status401Unauthorized
                });

            case AddSubmissionResultType.Forbiddance:
                return(new ObjectResult(result)
                {
                    StatusCode = StatusCodes.Status403Forbidden
                });

            case AddSubmissionResultType.ContestNotFound:
                return(NotFound(result));

            case AddSubmissionResultType.ProblemNotFound:
                return(NotFound(result));

            case AddSubmissionResultType.FileTooBig:
                return(BadRequest(result));

            case AddSubmissionResultType.Wrong:
                return(new ObjectResult(result)
                {
                    StatusCode = StatusCodes.Status422UnprocessableEntity
                });

            case AddSubmissionResultType.Error:
                return(BadRequest(result));

            case AddSubmissionResultType.Ok:
                return(Ok(result));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }