示例#1
0
        public async Task <Document> SaveDocumentAsync(Stream file, string fileName, int size, string userId)
        {
            var document = new Document(userId, fileName, size);

            await _blobStorage.CreateContainerAsync(userId);

            await _blobStorage.CreateBlobAsync(userId, document.Id, file);

            var result = await _documentRepository.CreateDocumentAsync(document, userId);

            return(result);
        }
示例#2
0
        protected override Task <object> Post(IHttpRequest request)
        {
            return(ProcessRequestAsync(request,
                                       r => _queryFactory.CreatePostQuery(r),
                                       async query =>
            {
                IDictionary <string, BlobInfo> fileInfos = null;

                if (query.Files != null)
                {
                    fileInfos = new Dictionary <string, BlobInfo>();

                    // Сохранение списка файлов
                    foreach (var file in query.Files)
                    {
                        // Сохранение файла в хранилище
                        var blobInfo = await _blobStorage.CreateBlobAsync(file.Name, file.ContentType, file.Value);

                        // Включение информации о файле в ответ
                        fileInfos[file.Key] = blobInfo;

                        // Установка ссылки на файл в документе
                        query.Document.SetProperty(file.Key, blobInfo);
                    }
                }

                DocumentUpdateResult status = null;
                DocumentValidationResult validationResult = null;

                try
                {
                    // Сохранение документа в хранилище
                    status = await _storage.SaveOneAsync(query.Document);
                }
                catch (DocumentStorageWriteException exception)
                {
                    validationResult = exception.WriteResult?.ValidationResult;
                }

                return new DocumentPostQueryResult
                {
                    DocumentId = query.Document._id,
                    FileInfos = fileInfos,
                    Status = status,
                    ValidationResult = validationResult
                };
            },
                                       _serviceHandler.OnBeforePost,
                                       _serviceHandler.OnAfterPost));
        }
示例#3
0
        public async Task <ActionResult> Create([FromForm] PersonForm personForm)
        {
            try
            {
                // now send blob up to Azure
                await _blobStorageService.CreateBlobAsync(
                    personForm.File.OpenReadStream(), personForm.File.FileName);

                // send to Cosmos
                await _personService.AddItemAsync(new Person
                {
                    Id   = personForm.Id,
                    Name = personForm.Name,
                    Ssn  = personForm.Ssn
                });

                //Ændre dette til at returnere et til detail view
                return(View("Person"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }