public async Task <IActionResult> GetMemberCommentAsync([FromHeader] String source, [FromRoute] RouteIdString route, [FromQuery] CommentGet item) { var response = new Response <Object>(); try { var express = Express.Begin <MemberComment>(true); express = express.And(a => a.NewsId == route.id && a.ParentId == 0 && a.IsEnable == 1); var result = await _IMemberCommentRepository.Query(express) .Select(a => new { CommentId = a.CommentId, NewsId = a.NewsId, ParentId = a.ParentId, MemberId = a.MemberId, MemberName = a.MemberName, CommentBody = a.CommentBody, CommentTime = a.CommentTime, QuoteId = a.QuoteId, QuoteName = a.QuoteName, Up = a.Up, Number = a.Number, Avatar = a.MemberInfos.Avatar, IsUp = item.MemberId > 0 ? a.MemberCommentUps.Any(b => b.MemberId == item.MemberId) : false }) .OrderBy(a => a.CommentTime) .ToPager(item.PageIndex.Value, item.PageSize.Value) .ToListAsync(); if (result.Count <= 0) { return(NoContent()); } else { response.Code = true; response.Data = result; } } catch (Exception ex) { response.SetError(ex, this._ILogger); } return(response.ToHttpResponse()); }
public IActionResult GetComment([FromQuery] CommentGet parameters) { var comment = (from comments in _context.Comments where comments.Id == parameters.CommentID select comments).Include(x => x.User).Single(); // 5 minute leeway before a comment is considered edited var isEdited = comment.Editdate.HasValue && comment.Editdate > comment.Createdon.AddMinutes(5); var commentData = new { comment = comment.Comment, date = Common.GetPSTTimeString(comment.Createdon), isEdited, username = comment.User.Username, userID = comment.User.Id }; return(Ok(commentData)); }