/// <summary> /// Commits an upload. /// </summary> /// <param name="tenantId">Tenant identifier.</param> /// <param name="uploadId">Upload identifier.</param> /// <param name="storageHierarchy">New location of upload, once committed. E.g. { "Uploads" > "Users" }.</param> /// <param name="unitOfWork">Unit of work.</param> public void Commit(long tenantId, long uploadId, List <string> storageHierarchy, IUnitOfWork unitOfWork = null) { // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null; // Try to commit upload try { // Get location of uncommitted uploads List <string> uncommittedStorageHierarchy = GetUncommittedStorageHierarchy(); // Get upload Upload upload = Read(tenantId, uploadId, uncommittedStorageHierarchy, unitOfWork ?? localUnitOfWork); // Set committed true upload.Committed = true; upload.Updated = DateTime.UtcNow; // Update upload so that committed is true switch (upload.UploadType) { case UploadType.Upload: _uploadRepository.UpdateUpload(upload, unitOfWork ?? localUnitOfWork); break; case UploadType.Image: _uploadRepository.UpdateImage((Image)upload, unitOfWork ?? localUnitOfWork); break; } // Create copy of upload with new storage hierarchy _storageService.Create(upload, storageHierarchy, unitOfWork ?? localUnitOfWork); // Delete uncommitted upload from storage _storageService.Delete(upload, uncommittedStorageHierarchy, unitOfWork ?? localUnitOfWork); // Commit work if local unit of work in place, then return newly allocated upload identifier if (localUnitOfWork != null) { localUnitOfWork.Commit(); } } catch { if (localUnitOfWork != null) { localUnitOfWork.Rollback(); } throw; } finally { if (localUnitOfWork != null) { localUnitOfWork.Dispose(); } } }
public async Task <ActionResult> UpdateUpload(Upload upload) { return(Ok(await _uploadRepository.UpdateUpload(upload))); }