public IActionResult GetAllAssets(string libid, [FromQuery] string lastId = null, [FromQuery] int count = 0) { Library lib = Context.FindObjectById <Library>(libid); if (lib == null) { return(NotFound()); } ICollection <Asset> assets = Context.GetAssets(lib, lastId, count); return(Ok(AssetValue.FromModel(assets))); }
public async Task <IActionResult> BasicUpload(IFormCollection formCollection, string libid) { Library lib = Context.FindObjectById <Library>(libid); if (lib == null) { return(NotFound()); } var files = formCollection.Files; List <AssetValue> results = new List <AssetValue>(); foreach (var formFile in files) { if (formFile.Length > 0) { var fileExt = Path.GetExtension(formFile.FileName); var fileId = $"{fileStore.CreateFileId()}{fileExt}"; var asset = new Asset { Name = formFile.FileName, Library = lib, CurrentVersion = 1 }; asset.AssetFiles.Add(new AssetFile { SourceFileName = formFile.FileName, MimeType = Mime.GetMimeFromExt(fileExt), ResourceId = fileId, ComponentType = FileComponent.RootFile, Version = 1 }); // add object to the db async. Task addTask = asset.AddToCollection(lib.AssetCollection); // write the content on the current thread using (Stream inStream = formFile.OpenReadStream()) fileStore.SaveFile(fileId, inStream); await addTask; results.Add(AssetValue.FromModel(asset)); } } return(Ok(results)); }
public IActionResult GetAsset(string libid, string assetId) { Library lib = Context.FindObjectById <Library>(libid); if (lib == null) { return(NotFound()); } Asset asset = Context.FindObjectById <Asset>(lib.AssetCollection, assetId); if (asset != null) { return(Ok(AssetValue.FromModel(asset))); } else { return(NotFound()); } }