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); }
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); }
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); } }
private void DeleteAttachments(DraftApplication draftApplication, UpdateDraftApplicationInput request) { draftApplication.DeleteAttachments( request.DeletedAttachments.Select(x => new StorageId(x))); }
private bool IfDeletedAttachmentExists(UpdateDraftApplicationInput request) { return(request.DeletedAttachments != null && request.DeletedAttachments.Any()); }
private Task <List <UploadedFile> > UploadFilesToStorage(UpdateDraftApplicationInput request) { return(this._fileStorageService.UploadFiles(request.AddedAttachments)); }
private List <EmployeeId> GetEmployees(UpdateDraftApplicationInput input) { return(input.SuspiciousEmployees.Select(x => new EmployeeId(x)).ToList()); }