public static async Task Add <T>(this IGameDatabase db, params string [] databaseIndexes) where T : IDatabaseEntry { var entryListData = await db.GetData <EntryListData>(typeof(T).Name); bool doAdd = false; if (entryListData == null) { entryListData = new EntryListData() { Type = typeof(T).Name }; //signal that we need to add this to the EntryListData itself doAdd = entryListData.Type != entryListData.GetType().Name; } foreach (var dbEntry in databaseIndexes) { if (!entryListData.Entries.Contains(dbEntry)) { entryListData.Entries.Add(dbEntry); } } if (doAdd) { await db.Add(entryListData); } await db.SaveData(entryListData); }
public static async Task AddTag(this IGameDatabase db, string unicode, string fancyName, ITagsList tagsList = null) { string emojiDatabaseIndex = string.Join(" ", Encoding.UTF8.GetBytes(unicode)); //now check if we exist TagData tagData = await db.GetData <TagData>(emojiDatabaseIndex); if (tagData == null) { tagData = new TagData() { Name = emojiDatabaseIndex, Emoji = unicode, FancyName = fancyName, }; await db.SaveData(tagData); } await db.Add(tagData); if (tagsList != null && !tagsList.Tags.Contains(emojiDatabaseIndex)) { tagsList.Tags.Add(emojiDatabaseIndex); } }
public static void Seed(this IGameDatabase source) { //Collection initializer var games = new [] { new Game() { Name = "TimeSplitters", Description = "2000", Price = 49.99M }, new Game() { Name = "Super Smash Bros. Ultimate", Description = "2018", Price = 59.99M }, new Game() { Name = "Steven Universe: Save the Light", Description = "2017", Price = 24.99M } }; foreach (var game in games) { source.Add(game); } }
static public void Seed(this IGameDatabase source) { //Collection initializer var games = new[] { new Game() { Name = "DOOM", Description = "Space Marine", Price = 49.99M }, new Game() { Name = "Oblivion", Description = "Medieval", Price = 89.99M }, new Game() { Name = "Fallout 76", Description = "Failed MMO", Price = 0.01M } }; foreach (var game in games) { source.Add(game); } }
/// <summary> /// <para>Adds this item to EntryListData of this type</para> /// <para> /// This overload calls back to IGameDatabase.Add( string databaseIndex ) /// NOTE: this will not save the data itself, call db.SaveData for that /// </para> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="db"></param> /// <param name="data"></param> public static async Task Add <T>(this IGameDatabase db, T data) where T : IDatabaseEntry { await db.Add <T>(data.DatabaseIndex); }