Пример #1
0
 public Task <IActionResult> GetAllComments([FromQuery] GetAllCommentsRequest request)
 {
     return(this.HandleRequest <GetAllCommentsRequest, GetAllCommentsResponse>(request));
 }
        public GetAllCommentsResponse GetAllComments(GetAllCommentsRequest request)
        {
            var response = new GetAllCommentsResponse();
            using (_unitOfWork)
                try
                {
                    Guard.ArgNotNull(request, "request");

                    Comment[] results = _unitOfWork.CommentRepository.Get(d => d.Id > 0).ToArray();
                    Guard.ArgNotNull(results, "results");

                    var quickInfoResults = new List<CommentQuickInfo>(results.Count());
                    quickInfoResults.AddRange(results.Select(
                        comment => new CommentQuickInfo
                                       {
                                           Id = comment.Id,
                                           Text = comment.Text,
                                           DataLastModified = comment.LastModified
                                       }));
                    response.Comments = quickInfoResults;
                    response.Success = true;
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.FailureInformation = ex.Message;
                    Logger.LogError("GetAllComments Method Failed", ex);
                }
            _unitOfWork.Dispose();
            return response;
        }