public void DeleteCategory(int cid)
        {
            Category c = db.Categories.Where(t => t.CategoryID == cid).FirstOrDefault();

            if (c != null)
            {
                db.Categories.Remove(c);
                db.SaveChanges();
            }
        }
예제 #2
0
        public void DeleteUser(int uid)
        {
            User u = db.Users.Where(t => t.UserID == uid).FirstOrDefault();

            if (u != null)
            {
                db.Users.Remove(u);
                db.SaveChanges();
            }
        }
        public void DeleteAnswers(int aid)
        {
            Answer ans = db.Answers.Where(t => t.AnswerID == aid).FirstOrDefault();

            if (ans != null)
            {
                db.Answers.Remove(ans);
                db.SaveChanges();
                qr.UpdateQuestionAnswerCount(ans.QuestionID, -1);
            }
        }
예제 #4
0
        public void UpdateVote(int aid, int uid, int value)
        {
            int updateValue = 0;

            if (value > 0)
            {
                updateValue = 1;
            }
            else if (value < 0)
            {
                updateValue = -1;
            }
            else
            {
                updateValue = 0;
            }
            Vote vote = db.Votes.Where(t => t.AnswerID == aid && t.UserID == uid).FirstOrDefault();

            if (vote != null)
            {
                vote.VoteValue = updateValue;
            }
            else
            {
                Vote newVote = new Vote()
                {
                    AnswerID  = aid,
                    UserID    = uid,
                    VoteValue = value
                };
                db.Votes.Add(newVote);
            }

            db.SaveChanges();
        }
        public void DeleteQuestion(int qid)
        {
            Question Q = db.Questions.Where(t => t.QuestionID == qid).FirstOrDefault();

            if (Q != null)
            {
                db.Questions.Remove(Q);
                db.SaveChanges();
            }
        }