Exemplo n.º 1
0
        public IActionResult LikeQuestion(LikesQuestions likesQuestions)
        {
            var repo = new QTRepository(_connectionString);

            repo.LikeQuestion(likesQuestions);
            return(Json('0'));
        }
Exemplo n.º 2
0
        public IActionResult PostAnswer(Answer answer)
        {
            var repo = new QTRepository(_connectionString);

            repo.AddAnswer(answer);
            return(Json('0'));
        }
Exemplo n.º 3
0
        public IActionResult ViewQuestion(int questionId)
        {
            if (questionId <= 0)
            {
                return(RedirectToAction("Index"));
            }

            var      repo     = new QTRepository(_connectionString);
            Question question = repo.GetQuestionById(questionId);

            if (question == null)
            {
                return(RedirectToAction("Index"));
            }

            var vm = new ViewQuestionViewModel {
                Question = question, IsAuthenticated = User.Identity.IsAuthenticated
            };

            if (vm.IsAuthenticated == true)
            {
                vm.User = repo.GetUserByEmail(User.Identity.Name);
            }

            return(View(vm));
        }
Exemplo n.º 4
0
        public IActionResult EmailAvailable(string email)     //this is used with ajax when user is signing up
        {
            var repo = new QTRepository(_connectionString);
            var vm   = new EmailAvailableViewModel();

            vm.IsAvailable = repo.IsEmailAvailable(email);
            return(Json(vm));
        }
Exemplo n.º 5
0
        public IActionResult NewQuestion(Question question, string tags)
        {
            List <string> tagList = new List <string>();

            tagList = tags.Split(' ').ToList();
            var repo = new QTRepository(_connectionString);

            question.DatePosted = DateTime.Now;
            question.UserId     = repo.GetUserByEmail(User.Identity.Name).Id;
            repo.AddQuestion(question, tagList);
            return(Redirect("/"));
        }
Exemplo n.º 6
0
        public IActionResult SignUp(string email, string password)
        {
            var repo = new QTRepository(_connectionString);

            repo.AddUser(email, password);
            var claims = new List <Claim>               //when sign up, this will also login the user
            {
                new Claim("user", email)
            };

            HttpContext.SignInAsync(new ClaimsPrincipal(
                                        new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait();
            return(Redirect("/"));
        }
Exemplo n.º 7
0
        public IActionResult Login(string email, string password)
        {
            var repo = new QTRepository(_connectionString);
            var user = repo.Login(email, password);

            if (user == null)
            {
                return(Redirect("/home/login"));
            }
            var claims = new List <Claim>
            {
                new Claim("user", email)
            };

            HttpContext.SignInAsync(new ClaimsPrincipal(
                                        new ClaimsIdentity(claims, "Cookies", "user", "role"))).Wait();
            return(Redirect("/"));
        }
Exemplo n.º 8
0
        public IActionResult Index()
        {
            var repo = new QTRepository(_connectionString);

            return(View(repo.GetQuestions()));
        }
Exemplo n.º 9
0
        public IActionResult GetUpdatedLikes(int questionId)
        {
            var repo = new QTRepository(_connectionString);

            return(Json(repo.GetCurrentLikes(questionId)));
        }
Exemplo n.º 10
0
        public IActionResult GetAnswersForQuestion(int questionId)
        {
            var repo = new QTRepository(_connectionString);

            return(Json(repo.GetAnswersForQuestion(questionId)));
        }