public async Task <ActionResult <EnrolleeViewModel> > AssignToaAgreementType(int enrolleeId, [FromBody] AgreementType agreementType) { if (!await _enrolleeService.EnrolleeExistsAsync(enrolleeId)) { return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}"))); } var assignedToaType = (agreementType == 0) ? null : (AgreementType?)agreementType; if (assignedToaType.HasValue && !Enum.IsDefined(typeof(AgreementType), agreementType)) { return(NotFound(ApiResponse.Message($"Agreement type not found with id {agreementType}."))); } if (assignedToaType.HasValue && !agreementType.IsEnrolleeAgreement()) { this.ModelState.AddModelError("AgreementType", "Agreement type must be a TOA."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } if (!await _enrolleeService.IsEnrolleeInStatusAsync(enrolleeId, StatusType.UnderReview)) { this.ModelState.AddModelError("Enrollee.CurrentStatus", "Assigned agreement type can not be updated when the current status is not 'Under Review'."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } await _enrolleeService.AssignToaAgreementType(enrolleeId, assignedToaType); await _businessEventService.CreateAdminActionEventAsync(enrolleeId, "Admin assigned agreement"); var updatedEnrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId); return(Ok(ApiResponse.Result(updatedEnrollee))); }