Exemplo n.º 1
0
 public ActionResult CreateFolder([FromBody] CreateFolderContentViewModel model)
 {
     try
     {
         _contentService.CreateFolder(model.FolderPath);
         return(Ok());
     }
     catch { return(BadRequest()); }
 }
        private async Task <bool> CreateContentFolders(OfferApplication application)
        {
            try
            {
                await _contentService.CreateFolder("" + application.ApplicationNumber, "/offer", "folder", "application-documents-folder");
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occurred while creating application folder for application {ApplicationNumber}", application.ApplicationNumber);
            }

            try
            {
                if (application.Documents != null)
                {
                    _logger.LogDebug("Create slots ");
                    var applicationDocuments = application.Documents.ToList();
                    foreach (var document in applicationDocuments)
                    {
                        var path = "/offer/" + document.ApplicationNumber;
                        try
                        {
                            await _contentService.CreateFolder("" + document.DocumentId, path, "folder", "generic-folder");
                        }
                        catch (Exception e)
                        {
                            _logger.LogError(e, "An error occurred while creating folder for document {DocumentId} on path {ContentPath}",
                                             document.DocumentId, path);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "An error occurred while creating documents folder for application {ApplicationNumber}", application.ApplicationNumber);
            }
            return(true);
        }
        public async Task <CommandStatus <ApplicationDocument> > Handle(CreateApplicationDocumentCommand message, CancellationToken cancellationToken)
        {
            if (message.Origin.Equals(DocumentOrigin.Product))
            {
                _logger.LogWarning("Tried to add application document \"{DocumentName}\" with Product origin outside of product definition, for application: {applicationNumber}",
                                   message.DocumentName, message.ApplicationNumber);
                var e = new Exception("Tried to add application document \"" + message.DocumentName +
                                      "\" with Product origin outside of product definition, for application: " + message.ApplicationNumber);
                return(new CommandStatus <ApplicationDocument> {
                    CommandResult = StandardCommandResult.BAD_REQUEST, Exception = e
                });
            }
            _logger.LogInformation("Creating application document for application: {applicationNumber}", message.ApplicationNumber);
            var document = Mapper.Map <CreateApplicationDocumentCommand, ApplicationDocument>(message);
            ApplicationDocument newDocument = null;

            try
            {
                newDocument = _applicationRepository.CreateApplicationDocument(message.ApplicationNumber, document);
            }
            catch (ApplicationNotFoundException ex)
            {
                return(new CommandStatus <ApplicationDocument> {
                    CommandResult = StandardCommandResult.NOT_FOUND, Exception = ex
                });
            }
            var finished = await _applicationRepository.UnitOfWork.SaveEntitiesAsync();

            await _auditClient.WriteLogEntry(AuditLogEntryAction.Create, AuditLogEntryStatus.Success, "document", message.ApplicationNumber.ToString(), "New document created", newDocument);

            if (finished)
            {
                try
                {
                    await _contentService.CreateFolder("" + newDocument.DocumentId, "/offer/" + newDocument.ApplicationNumber, "folder", "generic-folder");

                    return(new CommandStatus <ApplicationDocument> {
                        Result = newDocument, CommandResult = StandardCommandResult.OK
                    });
                }
                catch (DuplicateObjectException)
                {
                    _logger.LogWarning("Got duplicate object exception while adding document for application {ApplicationNumber}", newDocument.ApplicationNumber);
                    return(new CommandStatus <ApplicationDocument> {
                        Result = newDocument, CommandResult = StandardCommandResult.OK
                    });
                }
                catch (Exception e)
                {
                    return(new CommandStatus <ApplicationDocument> {
                        CommandResult = StandardCommandResult.INTERNAL_ERROR, Exception = e
                    });
                }
            }
            else
            {
                _logger.LogError("An error occurred while creating application document named '{documentName}' for application {applicationNumber}",
                                 message.DocumentName, message.ApplicationNumber);
                return(new CommandStatus <ApplicationDocument> {
                    CommandResult = StandardCommandResult.INTERNAL_ERROR
                });
            }
        }