public async Task <ActionResult <Enrollee> > CreateEnrollee(Enrollee enrollee) { if (enrollee == null) { this.ModelState.AddModelError("Enrollee", "Could not create an enrollee, the passed in Enrollee cannot be null."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } if (!User.CanEdit(enrollee)) { return(Forbid()); } // Check to see if this userId is already an enrollee, if so, reject creating another if (await _enrolleeService.EnrolleeUserIdExistsAsync(enrollee.UserId)) { this.ModelState.AddModelError("Enrollee.UserId", "An enrollee already exists for this User Id, only one enrollee is allowed per User Id."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } enrollee.IdentityAssuranceLevel = User.GetIdentityAssuranceLevel(); var createdEnrolleeId = await _enrolleeService.CreateEnrolleeAsync(enrollee); return(CreatedAtAction( nameof(GetEnrolleeById), new { enrolleeId = createdEnrolleeId }, ApiResponse.Result(enrollee) )); }
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) )); }
public async Task <ActionResult <Enrollee> > CreateEnrollee(Enrollee enrollee) { if (enrollee == null) { this.ModelState.AddModelError("Enrollee", "Could not create an enrollee, the passed in Enrollee cannot be null."); return(BadRequest(new ApiBadRequestResponse(this.ModelState))); } // Check to see if this userId is already an enrollee, if so, reject creating another var existingEnrolment = await _enrolleeService.GetEnrolleeForUserIdAsync(enrollee.UserId); if (existingEnrolment != null) { this.ModelState.AddModelError("Enrollee.UserId", "An enrollee already exists for this User Id, only one enrollee is allowed per User Id."); return(BadRequest(new ApiBadRequestResponse(this.ModelState))); } var createdEnrolleeId = await _enrolleeService.CreateEnrolleeAsync(enrollee); return(CreatedAtAction(nameof(GetEnrolleeById), new { enrolleeId = createdEnrolleeId }, new ApiCreatedResponse <Enrollee>(enrollee))); }