public static bool TryAdd(NameSuggestDbContext dbContext, int suggestId, string userIp) { var isVoted = dbContext.UpVotes.Any(x => x.IpUser == userIp && x.Suggestion.SuggestionID == suggestId); if (isVoted) { return(false); } UpVote upVote = new UpVote() { IpUser = userIp, SuggestionId = suggestId }; dbContext.UpVotes.Add(upVote); dbContext.SaveChanges(); return(true); }
public static bool TryAdd(NameSuggestDbContext dbContext, string suggestionValue, string userIp) { var suggestion = dbContext.Suggestions.FirstOrDefault(x => x.SuggestionValue == suggestionValue); return(suggestion != null && TryAdd(dbContext, suggestion.SuggestionID, userIp)); }