public void DeleteCategory(int id) { var category = db.Categories.Where(x => x.CategoryId == id).FirstOrDefault(); if (category != null) { db.Categories.Remove(category); db.SaveChanges(); } }
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 InsertUser(User user) { db.Users.Add(user); 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); }