コード例 #1
0
        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();
        }
コード例 #2
0
 public void InsertCategory(Category category)
 {
     knowledgesharingDB.Categories.Add(category);
     knowledgesharingDB.SaveChanges();
 }
コード例 #3
0
 public void InsertAnswer(Answer answer)
 {
     knowledgesharingDB.Answers.Add(answer);
     knowledgesharingDB.SaveChanges();
     questionRepository.UpdateQuestionAnswersCount(answer.QuestionID, 1);
 }
コード例 #4
0
 public void InsertUser(User user)
 {
     knowledgesharingDB.Users.Add(user);
     knowledgesharingDB.SaveChanges();
 }
コード例 #5
0
 public void InsertQuestion(Question question)
 {
     knowledgesharingDB.Questions.Add(question);
     knowledgesharingDB.SaveChanges();
 }