示例#1
0
        private CommitmentChangeType DetermineHistoryChangeType(LastAction latestAction, EditStatus updatedEditStatus)
        {
            var changeType = CommitmentChangeType.SentForReview;

            if (updatedEditStatus == EditStatus.Both && latestAction == LastAction.Approve)
            {
                changeType = CommitmentChangeType.FinalApproval;
            }
            else if (latestAction == LastAction.Approve)
            {
                changeType = CommitmentChangeType.SentForApproval;
            }

            return(changeType);
        }
示例#2
0
        private bool UpdateApprenticeshipStatuses(UpdateCommitmentAgreementCommand command, LastAction latestAction, Apprenticeship apprenticeship)
        {
            bool hasChanged = false;

            var newApprenticeshipAgreementStatus = _apprenticeshipUpdateRules.DetermineNewAgreementStatus(apprenticeship.AgreementStatus, command.Caller.CallerType, latestAction);
            var newApprenticeshipPaymentStatus   = _apprenticeshipUpdateRules.DetermineNewPaymentStatus(apprenticeship.PaymentStatus, newApprenticeshipAgreementStatus);

            if (apprenticeship.AgreementStatus != newApprenticeshipAgreementStatus)
            {
                apprenticeship.AgreementStatus = newApprenticeshipAgreementStatus;
                if (apprenticeship.AgreementStatus == AgreementStatus.BothAgreed && !apprenticeship.AgreedOn.HasValue)
                {
                    apprenticeship.AgreedOn = _currentDateTime.Now;
                }
                hasChanged = true;
            }

            if (apprenticeship.PaymentStatus != newApprenticeshipPaymentStatus)
            {
                apprenticeship.PaymentStatus = newApprenticeshipPaymentStatus;
                hasChanged = true;
            }
            return(hasChanged);
        }
示例#3
0
        private async Task <IList <Apprenticeship> > UpdateApprenticeshipAgreementStatuses(UpdateCommitmentAgreementCommand command, Commitment commitment, LastAction latestAction)
        {
            var updatedApprenticeships = new List <Apprenticeship>();

            foreach (var apprenticeship in commitment.Apprenticeships)
            {
                //todo: extract status stuff outside loop and set all apprenticeships to same agreement status?
                var hasChanged = UpdateApprenticeshipStatuses(command, latestAction, apprenticeship);

                if (hasChanged)
                {
                    updatedApprenticeships.Add(apprenticeship);
                }
            }

            await _apprenticeshipRepository.UpdateApprenticeshipStatuses(updatedApprenticeships);

            return(updatedApprenticeships);
        }
示例#4
0
        private async Task UpdateCommitmentStatuses(UpdateCommitmentAgreementCommand command, Commitment updatedCommitment, bool areAnyApprenticeshipsPendingAgreement, LastAction latestAction)
        {
            var updatedEditStatus = _apprenticeshipUpdateRules.DetermineNewEditStatus(updatedCommitment.EditStatus, command.Caller.CallerType, areAnyApprenticeshipsPendingAgreement,
                                                                                      updatedCommitment.Apprenticeships.Count, latestAction);
            var changeType     = DetermineHistoryChangeType(latestAction, updatedEditStatus);
            var historyService = new HistoryService(_historyRepository);

            historyService.TrackUpdate(updatedCommitment, changeType.ToString(), updatedCommitment.Id, null, command.Caller.CallerType, command.UserId, updatedCommitment.ProviderId, updatedCommitment.EmployerAccountId, command.LastUpdatedByName);

            updatedCommitment.EditStatus       = updatedEditStatus;
            updatedCommitment.CommitmentStatus = _apprenticeshipUpdateRules.DetermineNewCommmitmentStatus(areAnyApprenticeshipsPendingAgreement);
            updatedCommitment.LastAction       = latestAction;

            SetLastUpdatedDetails(command, updatedCommitment);
            await _commitmentRepository.UpdateCommitment(updatedCommitment);

            await historyService.Save();
        }