public StoreStruct getIcecream(string id) { var iceId = Query <IceCream> .EQ(p => p.ID, new MongoDB.Bson.ObjectId(id)); StoreStruct ice = new StoreStruct(); var iceCream = _dbContext._database.GetCollection <IceCream>("iceCreams").FindOne(iceId); ice.IceCreams.Add(iceCream); ice.Store = _dbContext._database.GetCollection <Store>("stores").AsQueryable().Where(r => r.Name.ToLower() == iceCream.Store.ToLower()).FirstOrDefault(); return(ice); }
public StoreStruct getStore(string id) { var storeId = Query <Store> .EQ(p => p.ID, new MongoDB.Bson.ObjectId(id)); Store storeDetails = _dbContext._database.GetCollection <Store>("stores").FindOne(storeId); var result = _dbContext._database.GetCollection <IceCream>("iceCreams").AsQueryable().Where(r => r.Store.ToLower() == storeDetails.Name.ToLower()).ToList(); StoreStruct store = new StoreStruct() { Store = storeDetails, IceCreams = result }; return(store); }
public async Task <StoreStruct> addRecommendation(string id, Recommendation recommendation) { var iceObjectId = Query <IceCream> .EQ(p => p.ID, new ObjectId(id)); var iceCream = _dbContext._database.GetCollection <IceCream>("iceCreams").FindOne(iceObjectId); //iceCream.ID = new ObjectId(id); StoreStruct ice = new StoreStruct(); ice.Store = _dbContext._database.GetCollection <Store>("stores").AsQueryable().Where(r => r.Name.ToLower() == iceCream.Store.ToLower()).FirstOrDefault(); if (iceCream.Recommendations == null) { iceCream.Recommendations = new List <Recommendation>(); } //**************************************************************************************************** #pragma warning disable CS4014 bool task = await RunAsync(recommendation.ImageUrl); #pragma warning disable CS4014 if (!task) { throw new Exception("The Picture has nothing to do with ice cream!"); } //**************************************************************************************************** iceCream.Recommendations.Add(recommendation); // Document Collections var collection = _dbContext._database.GetCollection <IceCream>("iceCreams"); // Document Update which need Id and Data to Update var result = collection.Update(iceObjectId, Update.Replace(iceCream), UpdateFlags.None); ice.IceCreams.Add(iceCream); return(ice); }