public async Task <Either <ActionResult, DataFileInfo> > Upload(Guid releaseId, IFormFile dataFormFile, IFormFile metaFormFile, string userName, Guid?replacingFileId = null, string subjectName = null) { return(await _persistenceHelper .CheckEntityExists <Release>(releaseId) .OnSuccess(_userService.CheckCanUpdateRelease) .OnSuccess(async release => { return await _persistenceHelper.CheckOptionalEntityExists <File>(replacingFileId) .OnSuccess(async replacingFile => { return await ValidateSubjectName(releaseId, subjectName, replacingFile) .OnSuccess(validSubjectName => _fileUploadsValidatorService .ValidateDataFilesForUpload(releaseId, dataFormFile, metaFormFile) // First, create with status uploading to prevent other users uploading the same datafile .OnSuccess(async() => await _importService.CreateImportTableRow(releaseId, dataFormFile.FileName.ToLower())) .OnSuccess(async() => { var dataFile = await _fileRepository.Create( releaseId: releaseId, filename: dataFormFile.FileName.ToLower(), type: FileType.Data, replacingFile: replacingFile); var metaFile = await _fileRepository.Create( releaseId: releaseId, filename: metaFormFile.FileName.ToLower(), Metadata); var dataInfo = GetDataFileMetaValues( name: validSubjectName, metaFileName: metaFile.Filename, userName: userName, numberOfRows: CalculateNumberOfRows(dataFormFile.OpenReadStream()) ); var metaDataInfo = GetMetaDataFileMetaValues( dataFileName: dataFile.Filename ); await UploadFileToStorage(dataFile, dataFormFile, dataInfo); await UploadFileToStorage(metaFile, metaFormFile, metaDataInfo); await _importService.Import( releaseId: releaseId, dataFileName: dataFile.Filename, metaFileName: metaFile.Filename, dataFile: dataFormFile, isZip: false); var blob = await _blobStorageService.GetBlob( PrivateFilesContainerName, dataFile.Path() ); return new DataFileInfo { Id = dataFile.Id, FileName = dataFile.Filename, Name = validSubjectName, Path = blob.Path, Size = blob.Size, MetaFileId = metaFile.Id, MetaFileName = blob.GetMetaFileName(), Rows = blob.GetNumberOfRows(), UserName = blob.GetUserName(), Status = IStatus.QUEUED, Created = blob.Created, Permissions = await _userService.GetDataFilePermissions(releaseId, blob.FileName) }; })); }); })); }