public Question GetQuestionById(string id)
        {
            var question = _repo.GetQuestionById(id);

            if (question == null)
            {
                throw new Exception("Bad Question ID");
            }
            return(question);
        }
Ejemplo n.º 2
0
        public IActionResult ViewQuestion(int id)
        {
            var repo = new QuestionsRepository(_connectionString);
            var vm   = new ViewQuestionViewModel();

            vm.Question = repo.GetQuestionById(id);
            vm.AskedBy  = repo.GetUserNameById(vm.Question.UserId);
            vm.CanLike  = repo.CanLike(id, GetCurrentUserId().Value);
            return(View(vm));
        }
Ejemplo n.º 3
0
        public IActionResult ViewQuestion(int id)
        {
            var connectionString = _connectionString;
            var repo             = new QuestionsRepository(connectionString);
            var question         = repo.GetQuestionById(id);
            var vm = new ViewQuestionViewModel()
            {
                Question = question
            };

            return(View(vm));
        }
Ejemplo n.º 4
0
        public IActionResult Update(int id)
        {
            var questionRepo = new QuestionsRepository(_connectionString);
            var userRepo     = new UsersRepository(_connectionString);
            var email        = User.Identity.Name;
            var user         = userRepo.GetUserByEmail(email);
            var question     = questionRepo.GetQuestionById(id);

            if (question.Likes.Any((likes => likes.QuestionId == question.Id)))
            {
                return(Redirect($"$/question/viewquestion?id={id}"));
            }
            questionRepo.UpdateLike(id, user);
            return(Json(id));
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        public IActionResult QuestionPage(int id)
        {
            var repository = new QuestionsRepository(_conn);

            var vm = new QuestionPageViewModel();

            vm.Question   = repository.GetQuestionById(id);
            vm.Tags       = repository.GetTagsByQuestion(vm.Question.QuestionsTags);
            vm.Answers    = repository.GetAnswersByQuestionId(id);
            vm.IsLoggedIn = User.Identity.IsAuthenticated;
            if (User.Identity.IsAuthenticated)
            {
                vm.User         = repository.GetUserByEmail(User.Identity.Name);
                vm.DidntLikeYet = repository.DidntLikeYet(id, vm.User.Id);
            }


            return(View(vm));
        }
Ejemplo n.º 7
0
        public IActionResult ViewQuestion(int questionId)
        {
            var questionsRepo = new QuestionsRepository(_connectionString);
            var userRepo      = new UsersRepository(_connectionString);
            var vm            = new ViewQuestionViewModel();
            var question      = questionsRepo.GetQuestionById(questionId);

            if (question == null)
            {
                return(Redirect("/"));
            }
            vm.Question       = question;
            vm.UserIsLoggedIn = User.Identity.IsAuthenticated;
            if (vm.UserIsLoggedIn)
            {
                vm.User = userRepo.GetByEmail(User.Identity.Name);
            }
            return(View(vm));
        }