public void UpdateUserCount(string token, int append) { //Update User var like = _context.LiveLikes.FirstOrDefault(l => string.Equals(l.Token, token)); if (like == null) { LiveLike Like = new LiveLike { IsEnabled = true, Token = token, Count = append > 0 ? append : 0, DCount = append < 0 ? append : 0, UpdateTimeUTC = DateTime.UtcNow, }; _context.LiveLikes.Add(Like); } else { if (append >= 0) { like.Count += append; } else { like.DCount += append; } like.UpdateTimeUTC = DateTime.UtcNow; } // Update Total var total = GetTotal(); total.Count += append; _context.SaveChanges(); }
private LiveLike GetTotal() { var total = _context.LiveLikes.FirstOrDefault(l => string.Equals(l.Token, "[Total]")); if (total == null) { LiveLike totalLike = new LiveLike { Token = "[Total]", IsEnabled = true, Count = 0, UpdateTimeUTC = DateTime.UtcNow, }; _context.LiveLikes.Add(totalLike); _context.SaveChanges(); return(totalLike); } else { return(total); } }