/// <summary> /// Upload the Assignment into Upload Respository /// </summary> /// <param name="file"></param> /// <param name="courseId"></param> /// <returns></returns> public async Task <Upload> UploadFileAsync(IFormFile file, string fileName) { Upload upload; try { using (Stream stream = new MemoryStream()) { string filePath = ""; file.OpenReadStream(); await file.CopyToAsync(stream); stream.Seek(0, SeekOrigin.Begin); bool doesBlockExitsAsync = await _blobHelper.DoesBlobExistsAsync("assignments", fileName); if (doesBlockExitsAsync) { bool deleteBlobAsync = await _blobHelper.DeleteBlobAsync("assignments", fileName); if (deleteBlobAsync) { filePath = await _blobHelper.UploadFileToBlobAsync("assignments", fileName, stream); } } else { filePath = await _blobHelper.UploadFileToBlobAsync("assignments", fileName, stream); } upload = new Upload { Id = Guid.NewGuid(), FileName = fileName, FilePath = filePath }; await _uploadRepository.UploadFileAsync(upload); } } catch (Exception ex) { Logging.Logger.LogException(ex); return(null); } return(upload); }