Beispiel #1
0
        public async Task <IActionResult> AddCommentLike([FromBody] VideoCommentVM vm)
        {
            if (vm.VideoCommentId <= 0)
            {
                return(NotFound());
            }

            var user = await _userManager.FindByIdAsync(User.Identity.Name);

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

            CommentLike commentLike = new CommentLike
            {
                UserId         = user.Id,
                VideoCommentId = vm.VideoCommentId
            };

            await _vclRepository.AddAsync(commentLike);

            await _vclRepository.CommitAsync();

            return(CreatedAtRoute("FindUserLikedComment", new
            {
                controller = "CardDetail",
                id = commentLike.VideoCommentId
            }, null));
        }
Beispiel #2
0
        public async Task <IActionResult> AddVideoComment([FromBody] VideoCommentVM vm)
        {
            if (!ModelState.IsValid)
            {
                string errorMsg = null;
                foreach (var m in ModelState.Values)
                {
                    foreach (var msg in m.Errors)
                    {
                        errorMsg = msg.ErrorMessage;
                    }
                }
                return(BadRequest(errorMsg));
            }

            var user = await _userManager.FindByIdAsync(User.Identity.Name);

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

            var ipAddress = _clientIP.GetClientIP();
            //var countryCode = await _clientIP.GetCountryCodeByIP(ipAddress);

            VideoComment newVideoComment = new VideoComment
            {
                Comment           = vm.Comment,
                DateCreated       = DateTime.Now,
                VideoPostId       = vm.VideoPostId,
                AuthorDisplayName = user.NickName.Trim(),
                UserId            = user.Id,
                IPAddress         = ipAddress,
                //Country = countryCode,
                IsSharer = await CheckSharer(user, vm.VideoPostId)
            };

            await _vcRepository.AddAsync(newVideoComment);

            await _vcRepository.CommitAsync();

            var videoCommentVM = Mapper.Map <VideoComment, VideoCommentVM>(newVideoComment);

            return(CreatedAtRoute("GetVideoComment", new
            {
                controller = "CardDetail",
                id = videoCommentVM.VideoCommentId
            }, videoCommentVM));
        }