/// <summary> /// Initializes Category collection in database with default values. /// </summary> /// <author>Anna Krebs</author> /// <param name="categoryValue"></param> /// <returns></returns> private async Task InitCategoryCollection(CategoryValue categoryValue) { var categoryValueString = categoryValue.ToString(); var sortOrder = Convert.ToInt32(categoryValue); var categoryCollection = _mongoContext.Database.GetCollection <Category>(nameof(Category)); var isDuplicate = await MongoHelper <Category> .IsDuplicate(Constants.Name, categoryValueString, categoryCollection, null); if (!isDuplicate) { await categoryCollection.InsertOneAsync( new Category { Name = categoryValueString, SortOrder = sortOrder }); Log.Info($"Inserted category {categoryValue} into database."); } }
/// <summary> /// Initializes Effect collection in database with default values. /// </summary> /// <author>Anna Krebs</author> /// <param name="name"></param> /// <param name="categoryValue"></param> /// <returns></returns> private async Task InitEffectCollection(string name, CategoryValue categoryValue) { var categoryValueString = categoryValue.ToString(); var effectCollection = _mongoContext.Database.GetCollection <Effect>(nameof(Effect)); var isDuplicate = await MongoHelper <Effect> .IsDuplicate(Constants.Name, name, effectCollection, null); if (!isDuplicate) { // Get category by name. var categoryCollection = _mongoContext.Database.GetCollection <Category>(nameof(Category)); var bsonFilter = Builders <Category> .Filter.Eq(nameof(Category.Name), categoryValueString); var category = await categoryCollection.Find(bsonFilter, _findOptions).SingleOrDefaultAsync(); var effect = new Effect { Name = name, CategoryId = category.ObjectId }; await effectCollection.InsertOneAsync(effect); Log.Info($"Inserted effect {name} with Id {effect.ObjectId} into database."); } }