예제 #1
0
        public void Like(int id)
        {
            var repo   = new QuestionsRepository(_connectionString);
            var email  = User.Identity.Name;
            var userId = repo.GetByEmail(email).Id;

            repo.AddLike(id, userId);
        }
예제 #2
0
        public IActionResult AddAnswer(Answer answer)
        {
            var repo = new QuestionsRepository(_connectionString);

            answer.DateAnswered = DateTime.Now;
            var email = User.Identity.Name;

            answer.UserId = repo.GetByEmail(email).Id;
            repo.AddAnswer(answer);
            return(Redirect($"/home/ViewQuestion?id={answer.QuestionId}"));
        }
예제 #3
0
        public IActionResult Add(Question question, IEnumerable <string> tags)
        {
            var repo = new QuestionsRepository(_connectionString);

            question.DatePosted = DateTime.Now;
            var email = User.Identity.Name;

            question.UserId = repo.GetByEmail(email).Id;
            repo.AddQuestion(question, tags);
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public IActionResult AddLike(int questionId)
        {
            var repo = new QuestionsRepository(_connectionString);
            var user = repo.GetByEmail(User.Identity.Name);
            var like = new Likes()
            {
                UserId     = user.Id,
                QuestionId = questionId
            };

            repo.AddLikes(like);
            return(Json(null));
        }
예제 #5
0
        private int?GetCurrentUserId()
        {
            var repo = new QuestionsRepository(_connectionString);

            if (!User.Identity.IsAuthenticated)
            {
                return(null);
            }

            var user = repo.GetByEmail(User.Identity.Name);

            if (user == null)
            {
                return(null);
            }

            return(user.Id);
        }
예제 #6
0
        public IActionResult ViewQuestion(int id)
        {
            var repo     = new QuestionsRepository(_connectionString);
            var question = repo.GetQuestionById(id);

            var email = User.Identity.Name;
            var user  = repo.GetByEmail(email);

            QuestionViewModel vm = new QuestionViewModel();

            vm.Question = question;
            if (user != null && user.Likes != null)
            {
                vm.Liked = user.Likes.Any(l => l.QuestionId == id);
            }

            return(View(vm));
        }