public void UpdateVote(int answerId, int userId, int value) { int updateValue; if (value > 0) { updateValue = 1; } else if (value < 0) { updateValue = -1; } else { updateValue = 0; } Vote vote = knowledgesharingDB.Votes.Where(temp => temp.AnswerID == answerId && temp.UserID == userId).FirstOrDefault(); if (vote != null) { vote.VoteValue = updateValue; } else { Vote newVote = new Vote() { AnswerID = answerId, UserID = userId, VoteValue = updateValue }; knowledgesharingDB.Votes.Add(newVote); } knowledgesharingDB.SaveChanges(); }
public void InsertCategory(Category category) { knowledgesharingDB.Categories.Add(category); knowledgesharingDB.SaveChanges(); }
public void InsertAnswer(Answer answer) { knowledgesharingDB.Answers.Add(answer); knowledgesharingDB.SaveChanges(); questionRepository.UpdateQuestionAnswersCount(answer.QuestionID, 1); }
public void InsertUser(User user) { knowledgesharingDB.Users.Add(user); knowledgesharingDB.SaveChanges(); }
public void InsertQuestion(Question question) { knowledgesharingDB.Questions.Add(question); knowledgesharingDB.SaveChanges(); }