public async Task <Document> SaveDocumentAsync(Stream fileStream, string fileName, long fileSize)
        {
            var id           = Guid.NewGuid().ToString();
            var fileLocation = await _contentStorage.SaveFile(fileStream, id + Path.GetExtension(fileName));

            var documentsCount = _documentsRepository.GetDocumentsCount();

            var document = new Document
            {
                Id       = id,
                Name     = fileName,
                FileSize = fileSize,
                Location = fileLocation,
                Position = documentsCount + 1
            };

            return(await _documentsRepository.AddDocumentAsync(document));
        }
        public async Task <UploadDocumentReturnModel> UploadDocument(UploadDocumentInputModel uploadDocumentInputModel)
        {
            using (var transaction = await _unitOfWork.BeginTransactionAsync().ConfigureAwait(false))
            {
                try
                {
                    DocumentType documentType = await GetDocumentType(uploadDocumentInputModel).ConfigureAwait(false);

                    var uploadFileName = _fileService.UploadFile(uploadDocumentInputModel.DocumentStream, uploadDocumentInputModel.DocumentName);

                    var document = new Document()
                    {
                        OriginalDocumentName = uploadDocumentInputModel.DocumentName,
                        DocumentName         = uploadFileName,
                        DocumentTypeId       = documentType.TypeId,
                        DocumentPath         = _fileService.GetUploadsPath(),
                        DocumentSize         = uploadDocumentInputModel.DocumentStream.Length,
                        UploadedBy           = uploadDocumentInputModel.UploadedBy,
                        UploadedDate         = _dateService.UtcNow
                    };

                    await _documentsRepository.AddDocumentAsync(document).ConfigureAwait(false);

                    await _unitOfWork.SaveChangesAsync().ConfigureAwait(false);

                    var returnModel = new UploadDocumentReturnModel
                    {
                        DocumentId           = document.DocumentId,
                        OriginalDocumentName = document.OriginalDocumentName,
                    };

                    transaction.Commit();

                    return(returnModel);
                }
                catch (Exception exception)
                {
                    transaction.Rollback();
                    throw new ServiceException(ErrorCodes.UploadDocumentException, "Something went wrong while uploading a document", exception);
                }
            }
        }