public void IncrementView(string itemKey) { lock (Mutex) // NOTE: This synchronization is not enough since there may be several instances of roles. { var result = GetOrCreateAnalyticInfo(itemKey); if (result.last_viewed.Date == DateTime.Today) { result.last_viewed = DateTime.Now; result.views_today += 1; result.views_total += 1; } else { result.last_viewed = DateTime.Now; result.views_average = result.views_total * result.views_average / (result.views_total - result.views_today + result.views_average); result.views_total += 1; result.views_today = 1; } AnalyticInfoStorage.Update(_context.BaseUri.OriginalString, result); //_context.UpdateObject(result); //_context.SaveChanges(); } }
public void IncrementVote(string itemKey, int vote) { lock (Mutex) // NOTE: This synchronization is not enough since there may be several instances of roles. { var result = GetOrCreateAnalyticInfo(itemKey); if (vote < 0) { result.NegativeVotes += -vote; } else { result.PositiveVotes += vote; } AnalyticInfoStorage.Update(_context.BaseUri.OriginalString, result); //_context.UpdateObject(result); //_context.SaveChanges(); } }