public async Task <ActionResult <EnrolleeViewModel> > CreateEnrollee(EnrolleeCreatePayload payload) { if (payload == null || payload.Enrollee == null) { ModelState.AddModelError("Enrollee", "Could not create an enrollee, the passed in Enrollee cannot be null."); return(BadRequest(ApiResponse.BadRequest(ModelState))); } if (await _enrolleeService.UserIdExistsAsync(User.GetPrimeUserId())) { ModelState.AddModelError("Enrollee.UserId", "An enrollee already exists for this User Id, only one enrollee is allowed per User Id."); return(BadRequest(ApiResponse.BadRequest(ModelState))); } var createModel = payload.Enrollee; createModel.MapConditionalProperties(User); if (createModel.IsUnder18()) { return(Forbid()); } string filename = null; if (!createModel.IsBcServicesCard()) { if (payload.IdentificationDocumentGuid != null) { filename = await _documentService.FinalizeDocumentUpload((Guid)payload.IdentificationDocumentGuid, "identification_document"); if (string.IsNullOrWhiteSpace(filename)) { ModelState.AddModelError("documentGuid", "Identification document could not be created; network error or upload is already submitted"); return(BadRequest(ApiResponse.BadRequest(ModelState))); } } else { ModelState.AddModelError("documentGuid", "Identification Document Guid was not supplied with request; Cannot create enrollee without identification."); return(BadRequest(ApiResponse.BadRequest(ModelState))); } } var createdEnrolleeId = await _enrolleeService.CreateEnrolleeAsync(createModel); var enrollee = await _enrolleeService.GetEnrolleeAsync(createdEnrolleeId); if (filename != null) { await _enrolleeService.CreateIdentificationDocument(enrollee.Id, (Guid)payload.IdentificationDocumentGuid, filename); } return(CreatedAtAction( nameof(GetEnrolleeById), new { enrolleeId = createdEnrolleeId }, ApiResponse.Result(enrollee) )); }