public bool SavePairRating(PairRecord record) { lock (locker) { PairRecord old = dbConnection.Table <PairRecord>().FirstOrDefault(); if (old == null) { dbConnection.Insert(record); return(true); } else { if (record.Errors < old.Errors) { record.Id = old.Id; dbConnection.Update(record, typeof(PairRecord)); return(true); } else { if (record.Errors == old.Errors && (record.GameTime < old.GameTime)) { record.Id = old.Id; dbConnection.Update(record, typeof(PairRecord)); return(true); } else { return(false); } } } } }
public void SaveResult() { Timer.Stop(); long mills = Timer.ElapsedMilliseconds; PairRecord record = new PairRecord { Errors = ErrorCounter, GameTime = mills, LasModified = DateTime.UtcNow }; App.Rest.UpdatePair(record); }
public async void UpdatePair(PairRecord record) { bool needsUpdate = Db.SavePairRating(record); if (needsUpdate) { object toSend = new { PairPlayerRatingId = 0, GameTime = record.GameTime, FailsNumber = record.Errors, LastModified = DateTime.UtcNow, PlayerId = Db.GetUser().ReturnableUser }; string jsonContent = JsonConvert.SerializeObject(toSend); StringContent data = new StringContent(jsonContent, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(pairRecordUrl, data); } }