Ejemplo n.º 1
0
        public List <CommentLikeDTO> GetAllCommentLikes()
        {
            var _CommentLikeList = new List <CommentLikeDTO>();

            try
            {
                string CurrUserId    = _session.GetString("UserId");
                var    _CommentLikes = _context.PictureCommentsLikes.ToList();
                for (int i = 0; i < _CommentLikes.Count; i++)
                {
                    var Commlikes = new CommentLikeDTO();
                    Commlikes.CommentId = _CommentLikes[i].CommentId;
                    if (_CommentLikes[i].UserId == int.Parse(CurrUserId))
                    {
                        Commlikes.CurrentUserLike = true;
                    }
                    Commlikes.TotalLike = _CommentLikes.Where(a => a.CommentId == _CommentLikes[i].CommentId).ToList().Count;
                    _CommentLikeList.Add(Commlikes);
                }
                return(_CommentLikeList);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task <int> likeComment([FromBody] CommentLikeDTO like)
        {
            try
            {
                var model = await context.commentLikes.SingleAsync(l => l.Id == like.Id);

                context.commentLikes.Remove(model);
                await context.SaveChangesAsync();

                return(-1);
            }
            catch
            {
                var model = mapper.Map <CommentLikeDTO, CommentLike>(like);
                model.date = DateTime.Now;
                await context.commentLikes.AddAsync(model);

                await context.SaveChangesAsync();

                return(model.Id);
            }
        }