示例#1
0
        public void DeleteCategory(int id)
        {
            var category = db.Categories.Where(x => x.CategoryId == id).FirstOrDefault();

            if (category != null)
            {
                db.Categories.Remove(category);
                db.SaveChanges();
            }
        }
示例#2
0
        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();
        }
示例#3
0
 public void InsertUser(User user)
 {
     db.Users.Add(user);
     db.SaveChanges();
 }
示例#4
0
 public void InsertQuestion(Question q)
 {
     db.Questions.Add(q);
     db.SaveChanges();
 }
示例#5
0
 public void InsertAnswer(Answer a)
 {
     db.Answers.Add(a);
     db.SaveChanges();
     qr.UpdateQuestionAnswersCount(a.QuestionId, 1);
 }