public void UpdateVote(int aid, int uid, int value) { int updateValue; if (value > 0) { updateValue = 1; } else if (value < 0) { updateValue = -1; } else { updateValue = 0; } Vote vote = db.Votes.Where(temp => temp.AnswerID == aid && temp.UserID == uid).FirstOrDefault(); if (vote != null) { vote.VoteValue = updateValue; } else { Vote newVote = new Vote() { AnswerID = aid, UserID = uid, VoteValue = updateValue }; db.Votes.Add(newVote); } db.SaveChanges(); }
public void InsertQuestion(Question q) { db.Questions.Add(q); db.SaveChanges(); }
public void InsertAnswer(Answer a) { db.Answers.Add(a); db.SaveChanges(); qr.UpdateQuestionAnswersCount(a.QuestionID, 1); }
public void InsertUser(User u) { db.Users.Add(u); db.SaveChanges(); }
public void InsertCategory(Category c) { db.Categories.Add(c); db.SaveChanges(); }