protected override async Task HandleCore(TriageDataLocksCommand command) { var validationResult = _validator.Validate(command); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } var dataLocksToBeUpdated = (await _dataLockRepository .GetDataLocks(command.ApprenticeshipId)) .Where(DataLockExtensions.UnHandled) .ToList(); var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(command.ApprenticeshipId); Validate(command, dataLocksToBeUpdated, apprenticeship); if (apprenticeship.HasHadDataLockSuccess && command.TriageStatus == TriageStatus.Change) { dataLocksToBeUpdated = dataLocksToBeUpdated.Where(DataLockExtensions.IsPriceOnly).ToList(); } if (dataLocksToBeUpdated.Any(m => m.TriageStatus == command.TriageStatus)) { throw new ValidationException($"Trying to update data lock for apprenticeship: {command.ApprenticeshipId} with the same TriageStatus ({command.TriageStatus}) "); } await _dataLockRepository.UpdateDataLockTriageStatus(dataLocksToBeUpdated.Select(m => m.DataLockEventId), command.TriageStatus); }
protected override async Task HandleCore(TriageDataLockCommand message) { var validationResult = _validator.Validate(message); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } var dataLock = await _dataLockRepository.GetDataLock(message.DataLockEventId); AssertDataLockBelongsToApprenticeship(message.ApprenticeshipId, dataLock); var triageStatus = (TriageStatus)message.TriageStatus; if (dataLock.TriageStatus == triageStatus) { _logger.Warn($"Trying to update data lock for apprenticeship: {message.ApprenticeshipId} with the same TriageStatus ({message.TriageStatus}) "); return; } AssertValidTriageStatus(triageStatus, dataLock); await AssertNoPendingApprenticeshipUpdate(dataLock, message.ApprenticeshipId); await _dataLockRepository.UpdateDataLockTriageStatus(message.DataLockEventId, triageStatus); }
protected override async Task HandleCore(RejectDataLockTriageCommand command) { var validationResult = _validator.Validate(command); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } var datalocks = await _dataLockRepository.GetDataLocks(command.ApprenticeshipId); var dataLocksToBeUpdated = datalocks .Where(DataLockExtensions.UnHandled) .Where(x => x.TriageStatus == TriageStatus.Change); var apprenticeship = await _apprenticeshipRepository.GetApprenticeship(command.ApprenticeshipId); if (apprenticeship.HasHadDataLockSuccess) { dataLocksToBeUpdated = dataLocksToBeUpdated.Where(DataLockExtensions.IsPriceOnly); } if (!dataLocksToBeUpdated.Any()) { return; } await _dataLockRepository.UpdateDataLockTriageStatus( dataLocksToBeUpdated.Select(m => m.DataLockEventId), TriageStatus.Unknown); }