public async Task <IActionResult> UpdateEnrollee(int enrolleeId, EnrolleeProfileViewModel enrolleeProfile, [FromQuery] bool beenThroughTheWizard) { var enrollee = await _enrolleeService.GetEnrolleeNoTrackingAsync(enrolleeId); if (enrollee == null) { return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}"))); } if (!User.CanEdit(enrollee)) { return(Forbid()); } // If the enrollee is not in the status of 'Editable', it cannot be updated if (!(await _enrolleeService.IsEnrolleeInStatusAsync(enrolleeId, StatusType.Editable))) { this.ModelState.AddModelError("Enrollee.CurrentStatus", "Enrollee can not be updated when the current status is not 'Editable'."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } await _enrolleeService.UpdateEnrolleeAsync(enrolleeId, enrolleeProfile, beenThroughTheWizard); return(NoContent()); }
public async void updateSingleEnrollee() { using (var scope = _factory.Server.Host.Services.CreateScope()) { Enrollee enrollee = this.CreateEnrollee(scope); string expectedFirstName = "NewFirstName"; Assert.NotEqual(expectedFirstName, enrollee.FirstName); var enrolleeProfile = new EnrolleeProfileViewModel { PreferredFirstName = expectedFirstName }; // create a request with an AUTH token var request = TestUtils.CreateRequest <EnrolleeProfileViewModel>(HttpMethod.Put, $"/api/enrollees/{enrollee.Id}", enrollee.UserId, enrolleeProfile); // try to update the enrollee var response = await _client.SendAsync(request); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); Enrollee updatedEnrollee = this.GetEnrollee(scope, enrollee.Id); Assert.Equal(expectedFirstName, updatedEnrollee.PreferredFirstName); } }
public async Task <ActionResult <Enrollee> > Submit(int enrolleeId, EnrolleeProfileViewModel updatedProfile) { var enrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId); if (enrollee == null) { return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}."))); } if (!User.CanEdit(enrollee)) { return(Forbid()); } if (updatedProfile == null) { this.ModelState.AddModelError("EnrolleeProfileViewModel", "New profile cannot be null."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } if (!(await _enrolleeService.IsEnrolleeInStatusAsync(enrolleeId, StatusType.Editable))) { this.ModelState.AddModelError("Enrollee.CurrentStatus", "Application can not be submitted when the current status is not 'Active'."); return(BadRequest(ApiResponse.BadRequest(this.ModelState))); } updatedProfile.IdentityAssuranceLevel = User.GetIdentityAssuranceLevel(); updatedProfile.IdentityProvider = User.GetIdentityProvider(); await _submissionService.SubmitApplicationAsync(enrolleeId, updatedProfile); enrollee = await _enrolleeService.GetEnrolleeAsync(enrolleeId); return(Ok(ApiResponse.Result(enrollee))); }
private async Task AssertAllowableChanges(bool expected, Enrollee enrollee, EnrolleeProfileViewModel profile) { var rule = new AllowableChangesRule(profile); Assert.Equal(expected, await rule.ProcessRule(enrollee)); AssertNoReasons(enrollee); }
public async Task <int> UpdateEnrolleeAsync(int enrolleeId, EnrolleeProfileViewModel enrolleeProfile, bool profileCompleted = false) { var enrollee = await _context.Enrollees .Include(e => e.MailingAddress) .Include(e => e.Certifications) .Include(e => e.Jobs) .Include(e => e.EnrolleeOrganizationTypes) .Include(e => e.SelfDeclarations) .SingleAsync(e => e.Id == enrolleeId); _context.Entry(enrollee).CurrentValues.SetValues(enrolleeProfile); UpdateMailingAddress(enrollee, enrolleeProfile.MailingAddress); ReplaceExistingItems(enrollee.Certifications, enrolleeProfile.Certifications, enrolleeId); ReplaceExistingItems(enrollee.Jobs, enrolleeProfile.Jobs, enrolleeId); ReplaceExistingItems(enrollee.EnrolleeOrganizationTypes, enrolleeProfile.EnrolleeOrganizationTypes, enrolleeId); ReplaceExistingItems(enrollee.SelfDeclarations, enrolleeProfile.SelfDeclarations, enrolleeId); // If profileCompleted is true, this is the first time the enrollee // has completed their profile by traversing the wizard, and indicates // a change in routing for the enrollee if (profileCompleted) { enrollee.ProfileCompleted = true; } try { return(await _context.SaveChangesAsync()); } catch (DbUpdateConcurrencyException) { return(0); } }
public static EnrolleeProfileViewModel ToViewModel(this Enrollee enrollee) { var serialized = JsonConvert.SerializeObject(enrollee); EnrolleeProfileViewModel profile = JsonConvert.DeserializeObject <EnrolleeProfileViewModel>(serialized); profile.IdentityAssuranceLevel = enrollee.IdentityAssuranceLevel; return(profile); }
public async void testAllowableChangesRule_SimpleDissallowedChange_PropertyOnChildObject() { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.MailingAddress.City = "Flavortown, USA"; await AssertAllowableChanges(false, enrollee, profile); }
public async void testAllowableChangesRule_SimpleDissallowedChange_SimpleProperty() { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.PreferredFirstName = "BIG CHANGES"; await AssertAllowableChanges(false, enrollee, profile); }
public async void testAllowableChangesRule_SimpleDissallowedChange_RemoveChildObject() { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.MailingAddress = null; await AssertAllowableChanges(false, enrollee, profile); }
/// <summary> /// All rules must pass for an update to be considered minor enough to not warrant going through the (Auto) adjudication proccess. /// These rules will not alter the enrollee object. /// </summary> public async Task <bool> QualifiesAsMinorUpdateAsync(Enrollee enrollee, EnrolleeProfileViewModel profileUpdate) { var rules = new List <MinorUpdateRule> { new DateRule(), new CurrentToaRule(_accessTermService), new AllowableChangesRule(profileUpdate) }; return(await ProcessRules(rules, enrollee)); }
public async void testAllowableChangesRule_AllowedUpdates() { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.ContactEmail += "change"; profile.ContactPhone += "change"; profile.VoicePhone += "change"; profile.VoiceExtension += "change"; await AssertAllowableChanges(true, enrollee, profile); }
public async void testUpdateEnrollee() { string expectedName = "ChangedName"; var testEnrollee = TestUtils.EnrolleeFaker.Generate(); testEnrollee.PreferredFirstName = "StartingName"; // create the enrollee directly to the context _dbContext.Enrollees.Add(testEnrollee); await _dbContext.SaveChangesAsync(); int enrolleeId = (int)testEnrollee.Id; // get the enrollee directly from the context Enrollee enrollee = await _dbContext.Enrollees .Include(e => e.PhysicalAddress) .Include(e => e.MailingAddress) .Include(e => e.Certifications) .Include(e => e.Jobs) .Include(e => e.EnrolleeOrganizationTypes) .AsNoTracking() .Where(e => e.Id == enrolleeId) .SingleOrDefaultAsync(); Assert.NotNull(enrollee); // make sure we are not tracking anything - i.e. isolate following transaction TestUtils.DetachAllEntities(_dbContext); // update the enrollee through the service layer code EnrolleeProfileViewModel enrolleeProfile = new EnrolleeProfileViewModel { PreferredFirstName = expectedName }; int updated = await _service.UpdateEnrolleeAsync(enrolleeId, enrolleeProfile); Assert.True(updated > 0); // get the updated enrollee directly from the context Enrollee updatedEnrollee = await _dbContext.Enrollees.FindAsync(enrolleeId); Assert.NotNull(updatedEnrollee); Assert.Equal(enrolleeId, updatedEnrollee.Id); Assert.Equal(expectedName, updatedEnrollee.PreferredFirstName); }
public async void testAllowableChangesRule_Jobs(bool?isObo, bool expected) { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); // Set the enrollee's user class via the access term if (isObo.HasValue) { enrollee.AccessTerms = new[] { new AccessTerm { AcceptedDate = DateTimeOffset.Now, UserClause = new UserClause { EnrolleeClassification = isObo == true ? PrimeConstants.PRIME_OBO : PrimeConstants.PRIME_RU } } }; } else { enrollee.AccessTerms = new AccessTerm[] { }; } // New job EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.Jobs.Add(new Job { Title = "Snake sweater knitter" }); await AssertAllowableChanges(expected, enrollee, profile); // Edit job profile = enrollee.ToViewModel(); profile.Jobs.First().Title = "Bespoke lifehack crafter"; await AssertAllowableChanges(expected, enrollee, profile); // Remove job profile = enrollee.ToViewModel(); profile.Jobs = profile.Jobs.Skip(1).ToList(); await AssertAllowableChanges(expected, enrollee, profile); }
public async void testAllowableChangesRule_Certifications() { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); // New cert EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.Certifications.Add(new Certification { CollegeCode = 1 }); await AssertAllowableChanges(false, enrollee, profile); // Edit cert profile = enrollee.ToViewModel(); profile.Certifications.First().LicenseNumber += "6"; await AssertAllowableChanges(false, enrollee, profile); // Remove cert profile = enrollee.ToViewModel(); profile.Certifications = profile.Certifications.Skip(1).ToList(); await AssertAllowableChanges(false, enrollee, profile); }
public async void testAllowableChangesRule_EnrolleeOrganizationTypes() { Enrollee enrollee = TestUtils.EnrolleeFaker.Generate(); // New org EnrolleeProfileViewModel profile = enrollee.ToViewModel(); profile.EnrolleeOrganizationTypes.Add(new EnrolleeOrganizationType { OrganizationTypeCode = 1 }); await AssertAllowableChanges(false, enrollee, profile); // Edit org profile = enrollee.ToViewModel(); profile.EnrolleeOrganizationTypes.First().OrganizationTypeCode++; await AssertAllowableChanges(false, enrollee, profile); // Remove org profile = enrollee.ToViewModel(); profile.EnrolleeOrganizationTypes = profile.EnrolleeOrganizationTypes.Skip(1).ToList(); await AssertAllowableChanges(false, enrollee, profile); }
public async Task SubmitApplicationAsync(int enrolleeId, EnrolleeProfileViewModel updatedProfile) { var enrollee = await _context.Enrollees .Include(e => e.MailingAddress) .Include(e => e.Certifications) .Include(e => e.Jobs) .Include(e => e.EnrolleeOrganizationTypes) .Include(e => e.AccessTerms) .ThenInclude(at => at.UserClause) .SingleOrDefaultAsync(e => e.Id == enrolleeId); bool minorUpdate = await _submissionRulesService.QualifiesAsMinorUpdateAsync(enrollee, updatedProfile); await _enrolleeService.UpdateEnrolleeAsync(enrolleeId, updatedProfile); if (minorUpdate) { return; } enrollee.AddEnrolmentStatus(StatusType.UnderReview); await _enroleeProfileVersionService.CreateEnrolleeProfileVersionAsync(enrollee); await _businessEventService.CreateStatusChangeEventAsync(enrollee.Id, "Submitted"); // TODO need robust issuance rules to be added since each submission shouldn't create // a new connection and issue a new credential // TODO when/where should a new credential be issued? // TODO check for an active connection // TODO check for issued credential await _verifiableCredentialService.CreateConnectionAsync(enrollee); await this.ProcessEnrolleeApplicationRules(enrolleeId); await _context.SaveChangesAsync(); }
public Task <int> UpdateEnrolleeAsync(int enrolleeId, EnrolleeProfileViewModel enrolleeProfile, bool profileCompleted) { throw new NotImplementedException(); }
public Task <bool> QualifiesAsMinorUpdateAsync(Enrollee enrollee, EnrolleeProfileViewModel profileUpdate) { throw new System.NotImplementedException(); }
public AllowableChangesRule(EnrolleeProfileViewModel updatedProfile) { _updatedProfile = updatedProfile; }