Example #1
0
        public IHttpActionResult LikeAnswer(int answerId)
        {
            var userId = User.Identity.GetUserId();

            if (_unitOfWork.AnswerLikeRepository.Any(al => al.AppUserId == userId && al.AnswerId == answerId))
            {
                return(BadRequest("User has already liked this answer."));
            }

            var answer = _unitOfWork.AnswerRepository.SingleOrDefault(a => a.Id == answerId, nameof(Answer.Question));

            if (answer == null)
            {
                return(BadRequest("Answer doesn't exist."));
            }

            _unitOfWork.AnswerLikeRepository.Add(new AnswerLike(userId, answerId));
            _unitOfWork.ActivityRepository.Add(
                Activity.ActivityLikeAnswer(userId, answer.Question.Id, answerId));

            _unitOfWork.Complete();

            return(Ok());
        }
Example #2
0
        public static Activity AddTestActivityLikeAnswerToDatabase(this iKnowContext context, int questionId, int answerId)
        {
            var activity = Activity.ActivityLikeAnswer(context.Users.First().Id, questionId, answerId);

            return(AddActivity(context, activity));
        }