public IActionResult CreateSubmission([FromBody] CreateCaseSubmissionRequest request) { var validator = new CreateCaseSubmissionRequestValidator(); var validationResults = validator.Validate(request); if (!validationResults.IsValid) { return(BadRequest(validationResults.ToString())); } try { var createdSubmission = _formSubmissionsUseCase.ExecutePost(request).Item1; return(CreatedAtAction(nameof(CreateSubmission), createdSubmission)); } catch (WorkerNotFoundException e) { return(UnprocessableEntity(e.Message)); } catch (PersonNotFoundException e) { return(UnprocessableEntity(e.Message)); } }
public (CaseSubmissionResponse, CaseSubmission) ExecutePost(CreateCaseSubmissionRequest request) { var worker = GetSanitisedWorker(request.CreatedBy); var resident = GetSanitisedResident(request.ResidentId); var dateTimeNow = DateTime.Now; var caseSubmission = new CaseSubmission { FormId = request.FormId, Residents = new List <Person> { resident }, Workers = new List <Worker> { worker }, CreatedAt = dateTimeNow, CreatedBy = worker, SubmissionState = SubmissionState.InProgress, EditHistory = new List <EditHistory <Worker> > { new EditHistory <Worker> { Worker = worker, EditTime = dateTimeNow } }, FormAnswers = new Dictionary <string, string>() }; _mongoGateway.InsertRecord(_collectionName, caseSubmission); return(caseSubmission.ToDomain().ToResponse(), caseSubmission); }