public async Task <TJsonObject> GetJsonObjectAsync <TJsonObject>( Func <GarlicBreadPersistenceContext, DbSet <JsonRow <TJsonObject> > > accessor, ulong guildId) where TJsonObject : JsonRootObject <TJsonObject>, new() { var row = accessor(this); var rowResult = await row.FindAsync(guildId); if (rowResult != null) { return(rowResult.Data); } rowResult = new JsonRow <TJsonObject> { GuildId = guildId }; row.Add(rowResult); await SaveChangesAsync(); return(rowResult.Data); }
public async Task <TJsonObject> ModifyJsonObjectAsync <TJsonObject>( Func <GarlicBreadPersistenceContext, DbSet <JsonRow <TJsonObject> > > accessor, ulong guildId, Action <TJsonObject> modifier) where TJsonObject : JsonRootObject <TJsonObject>, new() { var row = accessor(this); var rowResult = await row.FindAsync(guildId); if (rowResult == null) { rowResult = new JsonRow <TJsonObject> { GuildId = guildId }; row.Add(rowResult); } modifier(rowResult.Data); Entry(rowResult).Property(d => d.Data).IsModified = true; await SaveChangesAsync(); return(rowResult.Data); }