Esempio n. 1
0
 public IncidentApplication CreateApplication(PostApplicationInput request, List <Attachment> attachments)
 {
     return(IncidentApplication.Create(
                new Title(request.Title),
                new Content(request.Content),
                new IncidentType(request.IncidentType),
                new EmployeeId(this._applicantContext.UserId),
                new List <EmployeeId>(
                    request.SuspiciousEmployees.Select(x => new EmployeeId(x))),
                attachments));
 }
Esempio n. 2
0
        //kbytner 06.08.2020 - add rollback uploaded attachments
        public async Task <IOutputPort> Handle(PostApplicationInput input, CancellationToken cancellationToken)
        {
            try
            {
                await this._validator.ValidateAndThrowAsync(input, cancellationToken);

                var attachments = new List <Attachment>();

                if (this.IfAddedAttachmentsExists(input))
                {
                    var files = await this.UploadFilesToStorage(input);

                    attachments = this._attachmentsFactory.CreateAttachments(files);
                }

                var incidentApplication = this._incidentApplicationFactory.CreateApplication(input, attachments);

                await this._incidentApplicationRepository.Create(incidentApplication, cancellationToken);

                if (this.CreatedFromDraft(input))
                {
                    this._draftApplicationRepository.Delete(new DraftApplicationId(input.DraftApplicationId.Value));
                }

                await this._eventProcesor.Process(incidentApplication.DomainEvents, cancellationToken);

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

            return(this._outputPort);
        }
Esempio n. 3
0
 private Task <List <UploadedFile> > UploadFilesToStorage(PostApplicationInput request)
 {
     return(this._fileStorageService.UploadFiles(request.Attachments));
 }
Esempio n. 4
0
 private bool IfAddedAttachmentsExists(PostApplicationInput request)
 {
     return(request.Attachments != null && request.Attachments.Any());
 }
Esempio n. 5
0
 private bool CreatedFromDraft(PostApplicationInput input)
 {
     return(input.DraftApplicationId.HasValue);
 }