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); }
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}")); }
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")); }
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)); }
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); }
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)); }