public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "promodata/{series}")] HttpRequestMessage req, string series, TraceWriter log) { IDatabase cache = RedisConnection.Connection.GetDatabase(); string redisKey = System.Environment.GetEnvironmentVariable("RedisKeyModelThree"); List <PromoData> promos = new List <PromoData>(); var length = cache.ListLength(redisKey); if (length > 0)//in redis { foreach (string item in cache.ListRange(redisKey, 0, (length - 1))) { promos.Add(JsonConvert.DeserializeObject <PromoData>(item)); } } else//get from mongodb and insert into redis { var promoCollection = MongoDBConnection.GetCollection <PromoData>("PromotionCollectionName"); promos = promoCollection.AsQueryable().OrderByDescending(p => p.CreatedTime).Take(5).ToList(); log.Info(promos.Count().ToString()); foreach (var promo in promos) { cache.ListLeftPush(redisKey, JsonConvert.SerializeObject(promo)); } cache.ListTrim(redisKey, 0, 4); } return(req.CreateResponse(HttpStatusCode.OK, promos, JsonMediaTypeFormatter.DefaultMediaType)); }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getall")] HttpRequestMessage req, TraceWriter log) { var driverData = MongoDBConnection.GetCollection <dynamic>("DriverCollectionName").Find(new BsonDocument()).ToList(); // Fetching the name from the path parameter in the request URL test return(req.CreateResponse(HttpStatusCode.OK, driverData, JsonMediaTypeFormatter.DefaultMediaType)); }
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "id/{name}")] HttpRequestMessage req, string name, TraceWriter log) { string query = "{VehicleId:{$eq:\"" + name + "\"}}"; var data = MongoDBConnection.GetCollection <dynamic>("DriverCollectionName").Find(query).ToList(); // Fetching the name from the path parameter in the request URL test return(req.CreateResponse(HttpStatusCode.OK, data, JsonMediaTypeFormatter.DefaultMediaType)); }
public PlaylistsRepository(MongoDBConnection connection) { if (connection == null) { throw new ArgumentNullException(nameof(connection)); } _collection = connection.GetCollection <Playlist>(CollectionName); }
public async static Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "content/{id}")] HttpRequestMessage req, string id, TraceWriter log) { //add content into MongoDB dynamic data = await req.Content.ReadAsStringAsync(); var circleData = JsonConvert.DeserializeObject <CircleData>(data as string); MongoDBConnection.GetCollection <CircleData>("CircleCollectionName").InsertOne(circleData); return(req.CreateResponse(HttpStatusCode.OK, "Inserted")); }