Ejemplo n.º 1
0
        public async Task <IOutputPort> Handle(UpdateDraftApplicationInput input, CancellationToken cancellationToken)
        {
            try
            {
                await this._validator.ValidateAndThrowAsync(input, cancellationToken);

                var draftApplication =
                    await this._draftApplicationRepository.GetById(new DraftApplicationId(input.DraftApplicationId),
                                                                   cancellationToken);

                this.UpdateApplicationData(draftApplication, input);
                await this._updateAttachments.Handle(draftApplication, input);

                this._draftApplicationRepository.Update(draftApplication);
                this.BuildOutput();
            }
            catch (BusinessRuleValidationException ex)
            {
                this._outputPort.WriteBusinessRuleError(ex.ToString());
            }
            catch (ValidationException ex)
            {
                this._outputPort.WriteInvalidInput(ex.MapToInvaliInputErrors());
            }

            return(this._outputPort);
        }
Ejemplo n.º 2
0
        private void UpdateApplicationData(DraftApplication draftApplication, UpdateDraftApplicationInput request)
        {
            var employees = this.GetEmployees(request);

            draftApplication.Update(
                new Content(request.Content),
                new Title(request.Title),
                new IncidentType(request.IncidentType),
                employees);
        }
Ejemplo n.º 3
0
        public async Task Handle(DraftApplication draftApplication, UpdateDraftApplicationInput input)
        {
            if (this.IfAddedAttachmentsExists(input))
            {
                var files = await this.UploadFilesToStorage(input);

                this.AddUploadedFilesAsAttachments(draftApplication, files);
            }

            if (this.IfDeletedAttachmentExists(input))
            {
                this.DeleteAttachments(draftApplication, input);
            }
        }
Ejemplo n.º 4
0
 private void DeleteAttachments(DraftApplication draftApplication,
                                UpdateDraftApplicationInput request)
 {
     draftApplication.DeleteAttachments(
         request.DeletedAttachments.Select(x => new StorageId(x)));
 }
Ejemplo n.º 5
0
 private bool IfDeletedAttachmentExists(UpdateDraftApplicationInput request)
 {
     return(request.DeletedAttachments != null && request.DeletedAttachments.Any());
 }
Ejemplo n.º 6
0
 private Task <List <UploadedFile> > UploadFilesToStorage(UpdateDraftApplicationInput request)
 {
     return(this._fileStorageService.UploadFiles(request.AddedAttachments));
 }
Ejemplo n.º 7
0
 private List <EmployeeId> GetEmployees(UpdateDraftApplicationInput input)
 {
     return(input.SuspiciousEmployees.Select(x => new EmployeeId(x)).ToList());
 }