Beispiel #1
0
        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)
                       ));
        }