Exemplo n.º 1
0
        public async Task <int> Handle(UpdateBatchLogReadyToPrintAddCertificatesRequest request, CancellationToken cancellationToken)
        {
            try
            {
                _unitOfWork.Begin();

                var excludedOverallGrades = new[] { "Fail" };
                var includedStatus        = new[] { "Submitted", "Reprint" };

                var certificateIds = await _certificateRepository.GetCertificatesReadyToPrint(
                    request.MaxCertificatesToBeAdded,
                    excludedOverallGrades,
                    includedStatus);

                if (certificateIds.Length > 0)
                {
                    await _certificateBatchLogRepository
                    .UpsertCertificatesReadyToPrintInBatch(certificateIds, request.BatchNumber);

                    await _certificateRepository.
                    UpdateCertificatesReadyToPrintInBatch(certificateIds, request.BatchNumber);
                }

                _unitOfWork.Commit();

                return(certificateIds.Length);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Failed to add ready to print certificates to batch {request.BatchNumber}");
                _unitOfWork.Rollback();
                throw;
            }
        }