/// <summary> /// Creates a cohort with a draft apprenticeship /// </summary> internal Cohort(long providerId, long accountId, long accountLegalEntityId, long?transferSenderId, DraftApprenticeshipDetails draftApprenticeshipDetails, Party originatingParty, UserInfo userInfo) : this(providerId, accountId, accountLegalEntityId, transferSenderId, originatingParty, userInfo) { CheckDraftApprenticeshipDetails(draftApprenticeshipDetails); ValidateDraftApprenticeshipDetails(draftApprenticeshipDetails, false); WithParty = originatingParty; EditStatus = originatingParty.ToEditStatus(); IsDraft = true; var draftApprenticeship = new DraftApprenticeship(draftApprenticeshipDetails, originatingParty); Apprenticeships.Add(draftApprenticeship); Publish(() => new DraftApprenticeshipCreatedEvent(draftApprenticeship.Id, Id, draftApprenticeship.Uln, draftApprenticeship.ReservationId, draftApprenticeship.CreatedOn.Value)); StartTrackingSession(UserAction.CreateCohort, originatingParty, accountId, providerId, userInfo); ChangeTrackingSession.TrackInsert(this); ChangeTrackingSession.TrackInsert(draftApprenticeship); ChangeTrackingSession.CompleteTrackingSession(); }
/// <summary> /// Creates an empty cohort with other party /// </summary> internal Cohort(long providerId, long accountId, long accountLegalEntityId, long?transferSenderId, Party originatingParty, string message, UserInfo userInfo) : this(providerId, accountId, accountLegalEntityId, transferSenderId, originatingParty, userInfo) { CheckIsEmployer(originatingParty); IsDraft = false; WithParty = originatingParty.GetOtherParty(); EditStatus = originatingParty.GetOtherParty().ToEditStatus(); LastAction = LastAction.Amend; if (message != null) { AddMessage(message, originatingParty, userInfo); } Publish(() => new CohortAssignedToProviderEvent(Id, DateTime.UtcNow)); StartTrackingSession(UserAction.CreateCohortWithOtherParty, originatingParty, accountId, providerId, userInfo); ChangeTrackingSession.TrackInsert(this); ChangeTrackingSession.CompleteTrackingSession(); }
public void UpdateProviderPriority(int priorityOrder, UserInfo userInfo) { StartTrackingSession(UserAction.UpdateCustomProviderPaymentPriorities, Party.Employer, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); PriorityOrder = priorityOrder; ChangeTrackingSession.CompleteTrackingSession(); }
public ChangeOfPartyRequest(Apprenticeship apprenticeship, ChangeOfPartyRequestType changeOfPartyType, Party originatingParty, long newPartyId, int?price, DateTime?startDate, DateTime?endDate, UserInfo userInfo, DateTime now) { CheckOriginatingParty(originatingParty); CheckRequestType(originatingParty, changeOfPartyType); CheckPrice(originatingParty, changeOfPartyType, price); StartTrackingSession(UserAction.CreateChangeOfPartyRequest, originatingParty, apprenticeship.Cohort.AccountLegalEntityId, apprenticeship.Cohort.ProviderId, userInfo); ApprenticeshipId = apprenticeship.Id; ChangeOfPartyType = changeOfPartyType; OriginatingParty = originatingParty; AccountLegalEntityId = changeOfPartyType == ChangeOfPartyRequestType.ChangeEmployer ? newPartyId : default(long?); ProviderId = changeOfPartyType == ChangeOfPartyRequestType.ChangeProvider ? newPartyId : default(long?); Price = price; StartDate = startDate; EndDate = endDate; Status = ChangeOfPartyRequestStatus.Pending; CreatedOn = now; LastUpdatedOn = now; ChangeTrackingSession.TrackInsert(this); ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ChangeOfPartyRequestCreatedEvent(Id, userInfo)); }
public void UpdateDraftApprenticeship(DraftApprenticeshipDetails draftApprenticeshipDetails, Party modifyingParty, UserInfo userInfo) { CheckIsWithParty(modifyingParty); var existingDraftApprenticeship = GetDraftApprenticeship(draftApprenticeshipDetails.Id); ValidateDraftApprenticeshipDetails(draftApprenticeshipDetails, ChangeOfPartyRequestId.HasValue); if (ChangeOfPartyRequestId.HasValue) { existingDraftApprenticeship.ValidateUpdateForChangeOfParty(draftApprenticeshipDetails); } StartTrackingSession(UserAction.UpdateDraftApprenticeship, modifyingParty, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); ChangeTrackingSession.TrackUpdate(existingDraftApprenticeship); if (existingDraftApprenticeship.IsOtherPartyApprovalRequiredForUpdate(draftApprenticeshipDetails)) { Approvals = Party.None; } existingDraftApprenticeship.Merge(draftApprenticeshipDetails, modifyingParty); UpdatedBy(modifyingParty, userInfo); LastUpdatedOn = DateTime.UtcNow; Publish(() => new DraftApprenticeshipUpdatedEvent(existingDraftApprenticeship.Id, Id, existingDraftApprenticeship.Uln, existingDraftApprenticeship.ReservationId, DateTime.UtcNow)); ChangeTrackingSession.CompleteTrackingSession(); }
public ChangeTrackingSessionTestsFixture Complete() { StateService.Setup(x => x.GetState(It.Is <object>(o => o == TestUpdateTrackableEntity))).Returns(TestUpdateUpdatedState); StateService.Setup(x => x.GetState(It.Is <object>(o => o == TestInsertTrackableEntity))).Returns(TestInsertUpdatedState); ChangeTrackingSession.CompleteTrackingSession(); return(this); }
public void RemoveCustomProviderPaymentPriority(Func <CustomProviderPaymentPriority> remove, UserInfo userInfo) { var item = remove(); StartTrackingSession(UserAction.UpdateCustomProviderPaymentPriorities, Party.Employer, Id, item.ProviderId, userInfo); ChangeTrackingSession.TrackDelete(item); ChangeTrackingSession.CompleteTrackingSession(); }
public void AddCustomProviderPaymentPriority(Func <CustomProviderPaymentPriority> add, UserInfo userInfo) { var item = add(); StartTrackingSession(UserAction.UpdateCustomProviderPaymentPriorities, Party.Employer, Id, item.ProviderId, userInfo); ChangeTrackingSession.TrackInsert(item); ChangeTrackingSession.CompleteTrackingSession(); }
public void RejectTransferRequest(UserInfo userInfo) { CheckIsWithParty(Party.TransferSender); StartTrackingSession(UserAction.RejectTransferRequest, Party.TransferSender, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); EditStatus = EditStatus.EmployerOnly; WithParty = Party.Employer; LastUpdatedOn = DateTime.UtcNow; ChangeTrackingSession.CompleteTrackingSession(); }
public virtual void SetCohort(Cohort cohort, UserInfo userInfo) { CheckCohortIdNotSet(cohort.Id); StartTrackingSession(UserAction.SetCohortId, OriginatingParty, cohort.EmployerAccountId, cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); CohortId = cohort.Id; ChangeTrackingSession.CompleteTrackingSession(); }
public virtual void SetNewApprenticeship(Apprenticeship apprenticeship, UserInfo userInfo, Party modifyingParty) { CheckNewApprenticeshipIdNotSet(apprenticeship.Id); StartTrackingSession(UserAction.SetNewApprenticeshipId, modifyingParty, apprenticeship.Cohort.EmployerAccountId, apprenticeship.Cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); NewApprenticeshipId = apprenticeship.Id; ChangeTrackingSession.CompleteTrackingSession(); }
public virtual void UpdateChangeOfPartyRequest(DraftApprenticeship draftApprenticeship, long employerAccountId, long providerId, UserInfo userInfo, Party modifyingParty) { StartTrackingSession(UserAction.UpdateChangeOfPartyRequest, modifyingParty, employerAccountId, providerId, userInfo); ChangeTrackingSession.TrackUpdate(this); Price = (int?)draftApprenticeship.Cost; StartDate = draftApprenticeship.StartDate; EndDate = draftApprenticeship.EndDate; ChangeTrackingSession.CompleteTrackingSession(); }
public virtual void Reject(Party modifyingParty, UserInfo userInfo) { CheckStatusIsPending(); StartTrackingSession(UserAction.RejectChangeOfPartyRequest, modifyingParty, Cohort.EmployerAccountId, Cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); Status = ChangeOfPartyRequestStatus.Rejected; ActionedOn = DateTime.UtcNow; ChangeTrackingSession.CompleteTrackingSession(); }
/// <summary> /// Creates a Cohort from a Change of Party Request /// </summary> internal Cohort(long providerId, long accountId, long accountLegalEntityId, Apprenticeship apprenticeship, Guid?reservationId, ChangeOfPartyRequest changeOfPartyRequest, UserInfo userInfo) : this(providerId, accountId, accountLegalEntityId, null, changeOfPartyRequest.OriginatingParty, userInfo) { ChangeOfPartyRequestId = changeOfPartyRequest.Id; Approvals = changeOfPartyRequest.IsPreApproved(); WithParty = changeOfPartyRequest.OriginatingParty.GetOtherParty(); IsDraft = false; if (changeOfPartyRequest.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeProvider) { TransferSenderId = apprenticeship.Cohort.TransferSenderId; } var draftApprenticeship = apprenticeship.CreateCopyForChangeOfParty(changeOfPartyRequest, reservationId); Apprenticeships.Add(draftApprenticeship); //Retained for backwards-compatibility: EditStatus = WithParty.ToEditStatus(); LastAction = LastAction.Amend; CommitmentStatus = CommitmentStatus.Active; Publish(() => new CohortWithChangeOfPartyCreatedEvent(Id, changeOfPartyRequest.Id, changeOfPartyRequest.OriginatingParty, DateTime.UtcNow, userInfo)); if (changeOfPartyRequest.ChangeOfPartyType == ChangeOfPartyRequestType.ChangeEmployer) { Publish(() => new CohortAssignedToEmployerEvent(Id, DateTime.UtcNow, Party.Provider)); } else { Publish(() => new CohortAssignedToProviderEvent(Id, DateTime.UtcNow)); } StartTrackingSession(UserAction.CreateCohortWithChangeOfParty, changeOfPartyRequest.OriginatingParty, accountId, providerId, userInfo); ChangeTrackingSession.TrackInsert(this); ChangeTrackingSession.TrackInsert(draftApprenticeship); ChangeTrackingSession.CompleteTrackingSession(); }
/// <summary> /// Creates an empty cohort without draft apprenticeship /// </summary> internal Cohort(long providerId, long accountId, long accountLegalEntityId, Party originatingParty, UserInfo userInfo) : this(providerId, accountId, accountLegalEntityId, null, originatingParty, userInfo) { WithParty = originatingParty; EditStatus = originatingParty.ToEditStatus(); IsDraft = true; StartTrackingSession(UserAction.CreateCohort, originatingParty, accountId, providerId, userInfo); ChangeTrackingSession.TrackInsert(this); ChangeTrackingSession.CompleteTrackingSession(); }
public virtual void UpdateCompletionDate(DateTime completionDate) { if (PaymentStatus != PaymentStatus.Completed) { throw new DomainException("CompletionDate", "The completion date can only be updated if Apprenticeship Status is Completed"); } StartTrackingSession(UserAction.UpdateCompletionDate, Party.None, Cohort.EmployerAccountId, Cohort.ProviderId, null); ChangeTrackingSession.TrackUpdate(this); CompletionDate = completionDate; ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ApprenticeshipCompletionDateUpdatedEvent { ApprenticeshipId = Id, CompletionDate = completionDate }); }
public void Delete(Party modifyingParty, UserInfo userInfo) { CheckIsWithParty(modifyingParty); StartTrackingSession(UserAction.DeleteCohort, modifyingParty, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); LastUpdatedOn = DateTime.UtcNow; MarkAsDeletedAndEmitCohortDeletedEvent(modifyingParty, userInfo); foreach (var draftApprenticeship in DraftApprenticeships.ToArray()) { RemoveDraftApprenticeship(draftApprenticeship); } ChangeTrackingSession.CompleteTrackingSession(); }
public void Reject(UserInfo userInfo, DateTime rejectedOn) { if (Status != TransferApprovalStatus.Pending) { throw new InvalidOperationException($"The TransferRequest {Id} is not in a Pending State and has a current status of {Status}"); } StartTrackingSession(UserAction.RejectTransferRequest, Party.TransferSender, Cohort.EmployerAccountId, Cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); TransferApprovalActionedByEmployerName = userInfo.UserDisplayName; TransferApprovalActionedByEmployerEmail = userInfo.UserEmail; Status = TransferApprovalStatus.Rejected; TransferApprovalActionedOn = rejectedOn; ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new TransferRequestRejectedEvent(Id, Cohort.Id, rejectedOn, userInfo)); }
public virtual void SendToOtherParty(Party modifyingParty, string message, UserInfo userInfo, DateTime now) { CheckIsEmployerOrProvider(modifyingParty); CheckIsWithParty(modifyingParty); StartTrackingSession(UserAction.SendCohort, modifyingParty, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); IsDraft = false; EditStatus = modifyingParty.GetOtherParty().ToEditStatus(); WithParty = modifyingParty.GetOtherParty(); LastAction = LastAction.Amend; CommitmentStatus = CommitmentStatus.Active; TransferApprovalStatus = null; AddMessage(message, modifyingParty, userInfo); UpdatedBy(modifyingParty, userInfo); LastUpdatedOn = DateTime.UtcNow; switch (WithParty) { case Party.Employer: Publish(() => new CohortAssignedToEmployerEvent(Id, now, modifyingParty)); break; case Party.Provider: Publish(() => new CohortAssignedToProviderEvent(Id, now)); break; default: throw new ArgumentOutOfRangeException(nameof(EditStatus)); } if (Approvals.HasFlag(Party.Provider)) { Publish(() => new ApprovedCohortReturnedToProviderEvent(Id, now)); } if (ChangeOfPartyRequestId.HasValue) { Publish(() => new CohortWithChangeOfPartyUpdatedEvent(Id, userInfo)); } Approvals = Party.None; ChangeTrackingSession.CompleteTrackingSession(); }
public virtual void Complete(DateTime completionDate) { var status = GetApprenticeshipStatus(completionDate); if (status != ApprenticeshipStatus.Live && status != ApprenticeshipStatus.Paused && status != ApprenticeshipStatus.Stopped) { throw new InvalidOperationException("Apprenticeship has to be Live, Paused, or Stopped in order to be completed"); } StartTrackingSession(UserAction.Complete, Party.None, Cohort.EmployerAccountId, Cohort.ProviderId, null); ChangeTrackingSession.TrackUpdate(this); PaymentStatus = PaymentStatus.Completed; CompletionDate = completionDate; ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ApprenticeshipCompletedEvent { ApprenticeshipId = Id, CompletionDate = completionDate }); }
public virtual bool IsApprovedByAllParties => WithParty == Party.None; //todo: use new Approvals flag public DraftApprenticeship AddDraftApprenticeship(DraftApprenticeshipDetails draftApprenticeshipDetails, Party creator, UserInfo userInfo) { CheckIsWithParty(creator); ValidateDraftApprenticeshipDetails(draftApprenticeshipDetails, false); StartTrackingSession(UserAction.AddDraftApprenticeship, creator, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); var draftApprenticeship = new DraftApprenticeship(draftApprenticeshipDetails, creator); Apprenticeships.Add(draftApprenticeship); Approvals = Party.None; UpdatedBy(creator, userInfo); LastUpdatedOn = DateTime.UtcNow; ChangeTrackingSession.TrackInsert(draftApprenticeship); ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new DraftApprenticeshipCreatedEvent(draftApprenticeship.Id, Id, draftApprenticeship.Uln, draftApprenticeship.ReservationId, draftApprenticeship.CreatedOn.Value)); return(draftApprenticeship); }
public void DeleteDraftApprenticeship(long draftApprenticeshipId, Party modifyingParty, UserInfo userInfo) { CheckIsWithParty(modifyingParty); var draftApprenticeship = DraftApprenticeships.Single(x => x.Id == draftApprenticeshipId); StartTrackingSession(UserAction.DeleteDraftApprenticeship, modifyingParty, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); RemoveDraftApprenticeship(draftApprenticeship); LastUpdatedOn = DateTime.UtcNow; Approvals = Party.None; ResetTransferSenderRejection(); if (!DraftApprenticeships.Any()) { MarkAsDeletedAndEmitCohortDeletedEvent(modifyingParty, userInfo); } ChangeTrackingSession.CompleteTrackingSession(); }
public void StopApprenticeship(DateTime stopDate, long accountId, bool madeRedundant, UserInfo userInfo, ICurrentDateTime currentDate, Party party) { ValidateApprenticeshipForStop(stopDate, accountId, currentDate); StartTrackingSession(UserAction.StopApprenticeship, party, Cohort.EmployerAccountId, Cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); PaymentStatus = PaymentStatus.Withdrawn; StopDate = stopDate; MadeRedundant = madeRedundant; ResolveDatalocks(stopDate); ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ApprenticeshipStoppedEvent { AppliedOn = currentDate.UtcNow, ApprenticeshipId = Id, StopDate = stopDate }); }
public void ResumeApprenticeship(ICurrentDateTime currentDateTime, Party party, UserInfo userInfo) { var resumedDate = currentDateTime.UtcNow; if (PaymentStatus != PaymentStatus.Paused) { throw new DomainException(nameof(PaymentStatus), "Only paused record can be activated"); } StartTrackingSession(UserAction.ResumeApprenticeship, party, Cohort.EmployerAccountId, Cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); PaymentStatus = PaymentStatus.Active; PauseDate = null; ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ApprenticeshipResumedEvent { ApprenticeshipId = Id, ResumedOn = resumedDate }); }
public void EditEndDateOfCompletedRecord(DateTime endDate, ICurrentDateTime currentDate, Party party, UserInfo userInfo) { if (PaymentStatus != PaymentStatus.Completed) { throw new DomainException(nameof(EndDate), "Only completed record end date can be changed"); } if (endDate > CompletionDate) { throw new DomainException(nameof(EndDate), "Planned training end date must be the same as or before the completion payment month"); } if (endDate <= StartDate) { throw new DomainException(nameof(EndDate), "Planned training end date must be after the planned training start date"); } StartTrackingSession(UserAction.EditEndDateOfCompletedApprentice, party, Cohort.EmployerAccountId, Cohort.ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); EndDate = endDate; ChangeTrackingSession.CompleteTrackingSession(); Publish(() => new ApprenticeshipUpdatedApprovedEvent { ApprenticeshipId = Id, ApprovedOn = currentDate.UtcNow, StartDate = StartDate.Value, EndDate = EndDate.Value, PriceEpisodes = GetPriceEpisodes(), TrainingType = ProgrammeType.Value, TrainingCode = CourseCode, Uln = Uln }); }
public virtual void Approve(Party modifyingParty, string message, UserInfo userInfo, DateTime now) { CheckIsEmployerOrProviderOrTransferSender(modifyingParty); CheckIsWithParty(modifyingParty); CheckIsCompleteForParty(modifyingParty); StartTrackingSession(UserAction.ApproveCohort, modifyingParty, EmployerAccountId, ProviderId, userInfo); ChangeTrackingSession.TrackUpdate(this); switch (modifyingParty) { case Party.Employer: case Party.Provider: { var otherParty = modifyingParty.GetOtherParty(); var isApprovedByOtherParty = Approvals.HasFlag(otherParty); IsDraft = false; EditStatus = isApprovedByOtherParty ? EditStatus.Both : otherParty.ToEditStatus(); WithParty = GetWithParty(otherParty, isApprovedByOtherParty); if (isApprovedByOtherParty) { EmployerAndProviderApprovedOn = DateTime.UtcNow; } LastAction = LastAction.Approve; CommitmentStatus = CommitmentStatus.Active; TransferApprovalStatus = GetTransferApprovalStatus(isApprovedByOtherParty); Approvals |= modifyingParty; AddMessage(message, modifyingParty, userInfo); UpdatedBy(modifyingParty, userInfo); LastUpdatedOn = DateTime.UtcNow; switch (WithParty) { case Party.Employer: Publish(() => new CohortAssignedToEmployerEvent(Id, now, modifyingParty)); break; case Party.Provider: Publish(() => new CohortAssignedToProviderEvent(Id, now)); break; case Party.TransferSender: Publish(() => new CohortTransferApprovalRequestedEvent(Id, now, modifyingParty)); break; } break; } case Party.TransferSender: TransferApprovalStatus = Types.TransferApprovalStatus.Approved; TransferApprovalActionedOn = now; WithParty = Party.None; break; default: throw new ArgumentOutOfRangeException(nameof(modifyingParty)); } if (Approvals.HasFlag(Party.Provider) && modifyingParty == Party.Employer) { Publish(() => new CohortApprovedByEmployerEvent(Id, now)); } if (IsApprovedByAllParties) { Publish(() => new CohortFullyApprovedEvent(Id, EmployerAccountId, ProviderId, now, modifyingParty, ChangeOfPartyRequestId, userInfo)); if (ChangeOfPartyRequestId.HasValue) { Publish(() => new CohortWithChangeOfPartyFullyApprovedEvent(Id, ChangeOfPartyRequestId.Value, now, modifyingParty, userInfo)); } } ChangeTrackingSession.CompleteTrackingSession(); }