public async Task <int> AddOrUpdateVote(int memeId, string userId, int value) { if (!await this.DoesArticleExistAsync(memeId)) { return(-1); } var vote = this.db.ArticleVotes .Where(m => m.ArticleId == memeId && m.UserId == userId) .FirstOrDefault(); value = this.NormalizeValue(value); if (vote == null) { vote = new ArticleVote { Count = value, ArticleId = memeId, UserId = userId }; this.db.Add(vote); } else { var difference = vote.Count + value; vote.Count = this.NormalizeValue(difference);; } await this.db.SaveChangesAsync(); return(await this.Votes(memeId)); }
public void AddVote(int articleID, int entityID, int score) { var vote = new ArticleVote() { ArticleID = articleID, EntityID = entityID, Score = score }; context.ArticleVotes.Add(vote); }
public void Remove(ArticleVote vote) { context.ArticleVotes.Remove(vote); }