public async Task <Apprenticeship> PostApprenticeships(string url, BulkApprenticeshipRequest bulkRequest)
        {
            var data    = JsonConvert.SerializeObject(bulkRequest);
            var content = await PostAsync(url, data);

            return(JsonConvert.DeserializeObject <Apprenticeship>(content));
        }
Example #2
0
        public async Task CreateApprenticeships(long providerId, long commitmentId, BulkApprenticeshipRequest bulkRequest)
        {
            _logger.Trace($"Bulk uploading {bulkRequest.Apprenticeships?.Count ?? 0} apprenticeships for commitment {commitmentId} for provider {providerId}", providerId: providerId, commitmentId: commitmentId);

            await _mediator.SendAsync(new BulkUploadApprenticeshipsCommand
            {
                Caller          = new Caller(providerId, CallerType.Provider),
                CommitmentId    = commitmentId,
                Apprenticeships = bulkRequest.Apprenticeships.Select(x => _apprenticeshipMapper.Map(x, CallerType.Provider)),
                UserId          = bulkRequest.UserId,
                UserName        = bulkRequest.LastUpdatedByInfo?.Name
            });

            _logger.Info($"Bulk uploaded {bulkRequest.Apprenticeships?.Count} apprenticeships for commitment {commitmentId} for provider {providerId}", providerId: providerId, commitmentId: commitmentId, recordCount: bulkRequest.Apprenticeships?.Count);
        }
        public async Task ShouldCallTheMediatorBulkUpload()
        {
            var providerId   = 1L;
            var commitmentId = 2L;
            var request      = new BulkApprenticeshipRequest
            {
                LastUpdatedByInfo = new LastUpdateInfo {
                    EmailAddress = "*****@*****.**", Name = "Bob"
                },
                UserId          = "User",
                Apprenticeships = new List <Types.Apprenticeship.Apprenticeship>()
            };

            await Orchestrator.CreateApprenticeships(providerId, commitmentId, request);

            MockMediator.Verify(
                x =>
                x.SendAsync(
                    It.Is <BulkUploadApprenticeshipsCommand>(
                        y =>
                        y.Caller.Id == providerId && y.Caller.CallerType == CallerType.Provider && y.CommitmentId == commitmentId && y.UserId == request.UserId &&
                        y.UserName == request.LastUpdatedByInfo.Name)), Times.Once);
        }
        protected override async Task Handle(BulkUploadApprenticeshipsCommand message, CancellationToken cancellationToken)
        {
            var stopwatch = Stopwatch.StartNew();

            var validationResult = new BulkUploadApprenticeshipsCommandValidator().Validate(message);

            if (!validationResult.IsValid)
            {
                throw new InvalidRequestException(validationResult.Errors);
            }

            var request = new BulkApprenticeshipRequest
            {
                UserId            = message.UserId,
                Apprenticeships   = message.Apprenticeships,
                LastUpdatedByInfo = new LastUpdateInfo {
                    EmailAddress = message.UserEmailAddress, Name = message.UserDisplayName
                }
            };

            await _providerCommitmentsApi.BulkUploadApprenticeships(message.ProviderId, message.CommitmentId, request);

            _logger.Trace($"Took {stopwatch.ElapsedMilliseconds} milliseconds to Bulk Upload {message.Apprenticeships.Count} apprentices to Commitments Api");
        }
Example #5
0
        public async Task BulkUploadApprenticeships(long providerId, long commitmentId, BulkApprenticeshipRequest bulkRequest)
        {
            var url = $"{_configuration.BaseUrl}api/provider/{providerId}/commitments/{commitmentId}/apprenticeships/bulk";

            await _commitmentHelper.PostApprenticeships(url, bulkRequest);
        }
Example #6
0
        public async Task <IHttpActionResult> PostBulkUpload(long providerId, long commitmentId, BulkApprenticeshipRequest bulkRequest)
        {
            // TODO: What should we return to the caller? list of urls?
            await _providerOrchestrator.CreateApprenticeships(providerId, commitmentId, bulkRequest);

            return(StatusCode(HttpStatusCode.NoContent));
        }