public IActionResult EditSubmissionAnswers(string submissionId, string stepId, [FromBody] UpdateFormSubmissionAnswersRequest request) { var validator = new UpdateFormSubmissionAnswersValidator(); var validationResults = validator.Validate(request); if (!validationResults.IsValid) { return(BadRequest(validationResults.ToString())); } try { return(Ok(_formSubmissionsUseCase.UpdateAnswers(submissionId, stepId, request))); } catch (GetSubmissionException e) { return(UnprocessableEntity(e.Message)); } catch (WorkerNotFoundException e) { return(UnprocessableEntity(e.Message)); } }
public CaseSubmissionResponse UpdateAnswers(string submissionId, string stepId, UpdateFormSubmissionAnswersRequest request) { var worker = GetSanitisedWorker(request.EditedBy); var submission = _mongoGateway.LoadRecordById <CaseSubmission>(_collectionName, ObjectId.Parse(submissionId)); if (submission == null) { throw new GetSubmissionException($"Submission with ID {submissionId} not found"); } if (submission.SubmissionState != SubmissionState.InProgress) { throw new UpdateSubmissionException("Cannot update answers, submission state not 'in progress'"); } submission.FormAnswers[stepId] = request.StepAnswers; submission.EditHistory.Add(new EditHistory <Worker> { Worker = worker, EditTime = DateTime.Now }); UpdateDateOfEvent(submission, request.DateOfEvent); UpdateTitle(submission, request.Title); _mongoGateway.UpsertRecord(_collectionName, ObjectId.Parse(submissionId), submission); return(submission.ToDomain().ToResponse()); }