public IActionResult Create([FromQuery] string apiKey, [FromBody] SubmissionFormViewModel submissionModel) { var supportedLanguages = Enum.GetValues(typeof(SupportedLanguages)) .Cast <SupportedLanguages>() .Select(l => l.ToString()) .ToList(); if (submissionModel == null) { return(BadRequest("Data cannot be empty")); } if (supportedLanguages.All(l => l != submissionModel.Language)) { return(BadRequest("Unsupported programming language")); } var serviceModel = Mapper.Map <PostedSubmission>(submissionModel); SubmissionResult result; try { result = submissionService.Create(serviceModel); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok(result)); }
public HttpResponse Create(string code, string ProblemId) { if (string.IsNullOrEmpty(code) || string.IsNullOrWhiteSpace(code)) { return(this.Redirect("/Create")); } submissionsService.Create(code, ProblemId, this.User); return(this.Redirect("/")); }
public HttpResponse Create(string problemId, string code) { if (string.IsNullOrEmpty(code) || code.Length < 30 || code.Length > 800) { return(Error("Code should be between 30 and 800 characters long.")); } var userId = GetUserId(); submissionsService.Create(problemId, userId, code); return(Redirect("/")); }
public IActionResult Create(SubmissionCreateInputModel model) { if (!ModelState.IsValid) { return(Redirect("/Submissions/Create?id=" + model.ProblemId)); } Submission submission = new Submission { Code = model.Code, ProblemId = model.ProblemId, UserId = this.User.Id, }; submissionsService.Create(submission); return(Redirect("/")); }