Ejemplo n.º 1
0
        public async Task <IActionResult> GetComment(Guid shopId, CommentRequestListViewModel commentRequestListViewModel)
        {
            var list = await _commentService.GetAllCommentByShop(shopId, commentRequestListViewModel);

            return(Ok(list));
        }
Ejemplo n.º 2
0
        public async Task <PagedList <CommentViewModel> > GetAllCommentByShop(Guid shopId, CommentRequestListViewModel commentRequestListViewModel)
        {
            var list = await GetAll().Where(x => (!commentRequestListViewModel.IsActive.HasValue || x.RecordActive == commentRequestListViewModel.IsActive) &&
                                            (x.ShopId == shopId) &&
                                            (string.IsNullOrEmpty(commentRequestListViewModel.Query) || (x.Content.Contains(commentRequestListViewModel.Query)))
                                            ).Select(x => new CommentViewModel(x)).ToListAsync();

            var commentViewModelProperties = GetAllPropertyNameOfCommentViewModel();

            var requestPropertyName = !string.IsNullOrEmpty(commentRequestListViewModel.SortName) ? commentRequestListViewModel.SortName.ToLower() : string.Empty;

            var matchedPropertyName = commentViewModelProperties.FirstOrDefault(x => x.ToLower() == requestPropertyName);

            if (string.IsNullOrEmpty(matchedPropertyName))
            {
                matchedPropertyName = "DateComment";
            }

            var type = typeof(CommentViewModel);

            var sortProperty = type.GetProperty(matchedPropertyName);

            list = commentRequestListViewModel.IsDesc ? list.OrderByDescending(x => sortProperty.GetValue(x, null)).ToList() : list.OrderBy(x => sortProperty.GetValue(x, null)).ToList();

            return(new PagedList <CommentViewModel>(list, commentRequestListViewModel.Skip ?? CommonConstants.Config.DEFAULT_SKIP, commentRequestListViewModel.Take ?? CommonConstants.Config.DEFAULT_TAKE));
        }