public async Task Vote(Question question, string userName, string vote) { var user = await _context.Users.SingleAsync(u => u.Name == userName); var questionVote = question.Votes.SingleOrDefault(v => v.UserId == user.Id); if (questionVote == null) { questionVote = new QuestionVote { Id = Guid.NewGuid(), User = user, Vote = vote }; } question.Votes.Add(questionVote); }