public IActionResult Post(CommentForAddDto commentForAddDto) { var currentUser = User.Claims.GetCurrentUser().Data; var mapResult = _mapper.Map <Comment>(commentForAddDto); mapResult.UserId = currentUser.Id; IResult result = _commentService.Add(mapResult); if (result.IsSuccessful) { CommentForListDto dto = new CommentForListDto { CommentId = mapResult.Id, Description = mapResult.Description, ShareDate = mapResult.ShareDate, UserId = mapResult.UserId, LastName = currentUser.LastName, FirstName = currentUser.FirstName }; var channelId = HttpContext.RequestServices.GetService <IPhotoService>().GetById(commentForAddDto.PhotoId).Data.ChannelId; this.RemoveCacheByContains(currentUser.Id + "/user-photos"); this.RemoveCacheByContains(currentUser.Id + "/user-comment-photos"); this.RemoveCacheByContains(currentUser.Id + "/like-photos"); this.RemoveCacheByContains(channelId + "/channel-photos"); this.RemoveCache(); return(Ok(dto)); } return(BadRequest(result.Message)); }
public async Task <IActionResult> AddComment(CommentForAddDto commentForAddDto) { var user = await _userManager.GetUserAsync(HttpContext.User); var comment = _mapper.Map <Comment>(commentForAddDto); comment.Owner = user; _repo.Add(comment); if (await _repo.Save()) { return(Ok("Comment added successfully !")); } throw new Exception("ERROR, Problem occured while adding the Comment"); }