private void ChangeStatus(AdminChangeStatusViewModel viewModel, long organisationId) { var organisation = dataRepository.Get <Organisation>(organisationId); User currentUser = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository); OrganisationStatuses previousStatus = organisation.Status; OrganisationStatuses newStatus = viewModel.NewStatus ?? OrganisationStatuses.Unknown; // Update the status organisation.SetStatus( newStatus, currentUser.UserId, viewModel.Reason); // [In]Activate users of the organisation if (newStatus == OrganisationStatuses.Active) { ActivateUsersOfOrganisation(organisation); } if (previousStatus == OrganisationStatuses.Active) { InactivateUsersOfOrganisation(organisation); } dataRepository.SaveChanges(); // Audit log auditLogger.AuditChangeToOrganisation( AuditedAction.AdminChangeOrganisationStatus, organisation, new { PreviousStatus = previousStatus, NewStatus = newStatus, viewModel.Reason }, User); }
public void SecurityCodeBusinessLogic_CreateSecurityCode_Only_Applies_To_Active_Or_Pending( OrganisationStatuses organisationStatus, bool expectedToFail) { // Arrange var securityCodeBusinessLogic = new SecurityCodeBusinessLogic(); var organisation = new Organisation { Status = organisationStatus }; var securityCodeExpiryDateTime = VirtualDateTime.Now.AddDays(7); // Act var creationResult = securityCodeBusinessLogic.CreateSecurityCode(organisation, securityCodeExpiryDateTime); // Assert var wasWasnt = expectedToFail ? "was" : "was not"; var didDidnt = expectedToFail ? "didn't" : "did"; Assert.AreEqual( expectedToFail, creationResult.Failed, $"Organisation status '{organisationStatus.ToString()}' {wasWasnt} expected to fail, but it {didDidnt}."); if (expectedToFail) { Assert.AreEqual( $"Generation of security codes cannot be performed for retired organisations. Organisation '' employerReference '' has status '{organisationStatus.ToString()}'.", creationResult.ErrorMessage.Description); } }
public void SetStatus(OrganisationStatuses status, long byUserId, string details = null) { if (status == Status && details == StatusDetails) { return; } OrganisationStatuses.Add(new OrganisationStatus() { OrganisationId = this.OrganisationId, Status = status, StatusDate = DateTime.Now, StatusDetails = details, ByUserId = byUserId }); Status = status; StatusDate = DateTime.Now; StatusDetails = details; }
public static Organisation GetConcreteOrganisation(string employerRef, string organisationName = "Org123", OrganisationStatuses organisationStatus = OrganisationStatuses.Active, ICollection <OrganisationStatus> organisationStatuses = null) { if (string.IsNullOrWhiteSpace(employerRef)) { var someId = new Random().Next(1000, 9999); employerRef = employerRef ?? $"Org_{someId}"; } // todo: Use Moq return(new Organisation { EmployerReference = employerRef, //OrganisationId = 123, OrganisationName = organisationName, LatestAddress = new OrganisationAddress(), SectorType = SectorTypes.Private, Status = organisationStatus, OrganisationStatuses = organisationStatuses ?? new List <OrganisationStatus>() }); }
public static CustomError HttpGoneCausedByOrganisationBeingInactive(OrganisationStatuses organisationStatus) { return(new CustomError(HttpStatusCode.Gone, $"Employer: The status of this organisation is '{organisationStatus}'")); }
public OrganisationBuilder WithStatus(OrganisationStatuses status) { this.status = status; return(this); }