Пример #1
0
        public PageData <CommentDto> List(CommentListDto dto)
        {
            var data   = _despository.List(dto);
            var result = Mapper.Map <PageData <CommentDto> >(data);

            return(result);
        }
        public async Task <IActionResult> GetComments(string slug, [FromQuery] int page = 1,
                                                      [FromQuery] int pageSize          = 5)
        {
            Tuple <int, List <Comment> > comments = await _commentService.FetchPageByProduct(slug);

            return(StatusCodeAndDtoWrapper.BuildSuccess(
                       CommentListDto.Build(comments.Item2, Request.Path, page, pageSize, comments.Item1)
                       ));
        }
Пример #3
0
        public async Task <IViewComponentResult> InvokeAsync(int id)
        {
            var commentListInDb = await _commentService.GetAllConfirmedByProducdIdAsync(id);

            var model = new CommentListDto
            {
                Comments     = commentListInDb,
                CommentCount = commentListInDb.Count
            };

            return(View(model));
        }
Пример #4
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>

        public PageData <TComment> List(CommentListDto dto)
        {
            StringBuilder condition = new StringBuilder();

            if (!String.IsNullOrEmpty(dto.Articleid))
            {
                condition.Append(" and articleid = @Articleid");
            }
            if (!String.IsNullOrEmpty(dto.Ip))
            {
                condition.Append(" and ip = @Ip");
            }
            if (!String.IsNullOrEmpty(dto.Nickname))
            {
                dto.Nickname = $"%{dto.Nickname}%";
                condition.Append(" and Nickname like @Nickname");
            }

            string modelQuery   = $@"select  *  from g_Comment   where 1=1 {condition} limit @startindex,@count";
            string countQuery   = "select count(1) from g_Comment";
            var    mixCondition = new
            {
                startindex = (dto.Page - 1) * dto.Size,
                count      = dto.Size
            };

            using (IDbConnection db = new MySqlConnection(constr))
            {
                List <TComment>     list      = db.Query <TComment>(modelQuery, mixCondition).ToList();
                int                 totalNum  = db.Query <int>(countQuery, mixCondition).SingleOrDefault();
                float               totlapage = (float)totalNum / dto.Size;
                PageData <TComment> result    = new PageData <TComment>
                {
                    Items          = list,
                    TotalNum       = totalNum,
                    TotalPageCount = (int)Math.Ceiling(totlapage)
                };
                return(result);
            }
        }