private YeastCollection CreateNewYeastCollection(string email, IMongoCollection <YeastCollection> collection) { var col = new YeastCollection { UserEmail = email, Yeast = DefaultLists.GetDefaultYeast().ToList() }; collection.InsertOne(col); return(col); }
public IEnumerable <Yeast> GetAllYeastForUser(string userEmail) { var db = _mongoClient.GetDatabase("BeerDb"); var query = Builders <YeastCollection> .Filter.Eq(f => f.UserEmail, userEmail); var mongoCollection = db.GetCollection <YeastCollection>("Yeast"); var yeastCollections = mongoCollection.Find(query).ToList(); YeastCollection col = null; if (yeastCollections == null || yeastCollections.Count == 0) { col = CreateNewYeastCollection(userEmail, mongoCollection); } else { //should only be one collection per user col = yeastCollections[0]; } return(col.Yeast); }