Example #1
0
        public CommentsResponse AddChartComment(ChartCommentDto comment)
        {
            var response = new CommentsResponse();

            try
            {
                var commentRepository = new ChartCommentRepository();
                var userRepository    = new UserProfileRepository();
                var newComment        = new ChartComment
                {
                    IdUser       = comment.IdUser,
                    DatePosted   = DateTime.Now,
                    Message      = comment.Message,
                    IdSmartChart = comment.IdSmartChart,
                    IsActive     = true
                };
                commentRepository.Add(newComment);
                commentRepository.SaveChanges();
                int userId = Convert.ToInt32(comment.IdUser);
                response.Comments.Add(new ChartCommentDto()
                {
                    Message    = newComment.Message,
                    DatePosted = newComment.DatePosted,
                    UserName   = userRepository.Query().FirstOrDefault(x => x.UserId == userId).UserName,
                    IdComment  = newComment.IdComment,
                    IdUser     = userId.ToString()
                });
                commentRepository.Dispose();
                response.Acknowledgment = true;
                response.Message        = "Success";
            }
            catch (Exception ex)
            {
                _logger.Error("Error adding comment. With the exception: " + ex.Message);
                response.Acknowledgment = false;
                response.Message        = "Error: " + ex.Message;
            }

            return(response);
        }
 public CommentsResponse AddChartComment(ChartCommentDto comment)
 {
     return(_commentService.AddChartComment(comment));
 }