public static async Task update_stats(stats s) { // Open database (create new if file doesn't exist) var store = new DataStore("stats.json"); // Get employee collection var collection = store.GetCollection <stats> (); if (collection.AsQueryable().Count() == 0) { await collection.InsertOneAsync(s); } else { await collection.ReplaceOneAsync(e => e.ID == s.ID, s); } store.Dispose(); }
public ActionResult Updateleaderboard([FromBody] apiModel model) { BadRequestResult bad = new BadRequestResult(); // apiModel model = Newtonsoft.Json.JsonConvert.DeserializeObject<apiModel>(raw); if (key.get_key(model.api_key) == null) { return(bad); } stats s = new stats { ID = 0, leaderboard = model.leaderboard }; stats.update_stats(s).GetAwaiter().GetResult(); OkResult ok = new OkResult(); return(ok); }
public static stats get_stats() { // Open database (create new if file doesn't exist) var store = new DataStore("stats.json"); // Get employee collection var collection = store.GetCollection <stats> (); stats stats = collection.AsQueryable().FirstOrDefault(); if (stats == null) { stats = new stats { leaderboard = new List <leaderboard> { new leaderboard { name = "No stats at this time", credits = 0 } } }; } store.Dispose(); return(stats); }