Example #1
0
        public async Task LikeAsync(CommentResponseLike commentResponseLike)
        {
            var entity = await FindByCondition(e => e.ResponseToCommentId == commentResponseLike.CommentResponseId)
                         .SingleOrDefaultAsync();

            entity?.CommentResponseLike.Add(commentResponseLike);
        }
Example #2
0
        public async Task <IActionResult> PutCommentResponseLike(int id, CommentResponseLike commentResponseLike)
        {
            if (id != commentResponseLike.Id)
            {
                return(BadRequest());
            }

            _context.Entry(commentResponseLike).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentResponseLikeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <CommentResponseLike> LikeAsync(int id, int userId)
        {
            bool ex = _repository.ResponseToComment.CheckIfLiked(id, userId);

            if (ex)
            {
                var like = new CommentResponseLike
                {
                    CommentResponseId = id,
                    UserId            = userId
                };
                await _repository.ResponseToComment.LikeAsync(like);

                await _repository.ResponseToComment.SaveAsync();

                return(like);
            }
            throw  new EntityIsAlreadyLiked();
        }
Example #4
0
        public async Task <ActionResult <CommentResponseLike> > PostCommentResponseLike(CommentResponseLikeViewModel vm)
        {
            CommentResponseLike like = new CommentResponseLike();
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user   = _context.Users.Find(userId);

            like.User         = user;
            like.Response     = _context.CommentResponses.Find(vm.CommentResponseId);
            like.LikeDateTime = DateTime.Now;

            if (_context.CommentResponseLikes.Where(x => x.User == user && x.Response == like.Response).Count() == 0)
            {
                _context.CommentResponseLikes.Add(like);
            }
            else
            {
                _context.CommentResponseLikes.RemoveRange(_context.CommentResponseLikes.Where(x => x.User == user && x.Response == like.Response).ToList());
            }

            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCommentResponseLike", new { id = like.Id }, like));
        }
Example #5
0
        public async Task <ActionResult <CommentResponseLike> > GetCommentResponseLike(int id, CommentResponseLike responseLike)
        {
            var commentResponseLike = await _context.CommentResponseLikes.FindAsync(id);

            if (commentResponseLike == null)
            {
                return(NotFound());
            }

            return(commentResponseLike);
        }