public IActionResult GetAllComments() { try { var result = _ctx.GetAllComment().Result.ToList(); return(Ok(result)); } catch (Exception ex) { _logger.LogError($"Unable to retrieve all comments.", ex); return(StatusCode(500, "There was an expection found at GetAllComments.")); } }
public IActionResult GetComments(int contentId) { try { var comments = new List <CommentEntity>(); if (_user != null) { if (contentId == 0) { var dbResult = _ctx.GetCommentsByAvatar(_user.Id); comments = dbResult.OrderBy(c => c.Id).ToList(); } if (contentId > 0) { var results = _ctx.GetAllComment().Result; comments = results.Where(c => c.CardEntityId == contentId).ToList(); } if (comments == null) { var message = $"No comments for user:{_user.Id} was found."; return(NotFound(message)); } var result = _mapper.Map <IEnumerable <CommentDto> >(comments); return(Ok(result)); } return(Unauthorized("Unable get comments. " + Message("unautherized"))); } catch (Exception ex) { _logger.LogError($"Unable to retrieve comments by user: {_user.Id}.", ex); return(StatusCode(500, "There was an expection found at GetComments.")); } }