public async Task <ContentStorageItem> Save(string id, string category, IContent content, CancellationToken cancellationToken) { var dbItem = await FindWithoutContent(id, category, cancellationToken); if (dbItem == null) { dbItem = new ContentStorageDbItem { Id = id, Category = category }; context.Items.Add(dbItem); } else { try { context.Items.Update(dbItem); } catch (InvalidOperationException) { dbItem = context.Items.Find(id, category); context.Items.Update(dbItem); } } dbItem.Timestamp = DateTimeOffset.UtcNow; dbItem.Content = await content.ReadAsByteArray(cancellationToken); dbItem.Size = content.Size; await context.SaveChangesAsync(cancellationToken); return(new ContentStorageItem(id, category, content, dbItem.Timestamp)); }
public ContentStorageItemContent(ContentStorageDbItem dbItem, IServiceScopeFactory serviceScopeFactory) { this.dbItem = dbItem ?? throw new ArgumentNullException(nameof(dbItem)); this.serviceScopeFactory = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory)); }
private ContentStorageItemContent GetItemContent(ContentStorageDbItem dbItem) => new ContentStorageItemContent(dbItem, serviceScopeFactory);