Ejemplo n.º 1
0
        public async Task <Document> UploadDocument(int customerId, DocumentCreate createRequest, CancellationToken cancellationToken)
        {
            bool existsCustomer = await uow.Set <Customer>().AnyAsync(x => x.Id == customerId, cancellationToken);

            if (!existsCustomer)
            {
                throw new ObjectNotFoundException("Customer nebyl nalezen!");
            }

            string containerName = ContainerPaths.CustomerDocuments(customerId);

            DocumentDbo document = mapper.Map <DocumentDbo>(createRequest, x => x.Items.Add("customerId", customerId));

            await azureStorageService.UploadAsync(createRequest.Datastream, containerName, document.Id.ToString(), cancellationToken);

            uow.Add(document);
            await uow.SaveChangesAsync(cancellationToken);

            return(mapper.Map <Document>(document));
        }