Ejemplo n.º 1
0
        //public List<TGuides> List()
        //{

        //    using (IDbConnection db = new MySqlConnection(constr))
        //    {



        //        return db.Query<TGuides>("Select * From Guides").ToList();
        //    }
        //}

        public PageData <TGuides> List(GuideListDto dto)
        {
            using (IDbConnection db = new MySqlConnection(constr))
            {
                StringBuilder condition = new StringBuilder();
                if (!String.IsNullOrEmpty(dto.Name))
                {
                    dto.Name = $"%{dto.Name}%";
                    condition.Append(" and name like @name");
                }
                if (!String.IsNullOrEmpty(dto.Mobile))
                {
                    dto.Mobile = $"%{dto.Mobile}%";
                    condition.Append(" and mobile like @mobile");
                }

                String modelQuery   = $@"select * from guides  where 1=1 {condition} limit @startindex,@count";
                string countQuery   = "select count(1) from guides";
                var    mixCondition = new
                {
                    startindex = (dto.Page - 1) * dto.Size,
                    count      = dto.Size
                };
                List <TGuides>     list      = db.Query <TGuides>(modelQuery, mixCondition).ToList();
                int                totalNum  = db.Query <Int32>(countQuery, mixCondition).SingleOrDefault <Int32>();
                decimal            totlapage = totalNum / dto.Size;
                PageData <TGuides> result    = new PageData <TGuides>
                {
                    Items          = list,
                    TotalNum       = totalNum,
                    TotalPageCount = (int)Math.Ceiling(totlapage)
                };
                return(result);
            }
        }
Ejemplo n.º 2
0
        public PageData <GuideDto> List(GuideListDto dto)
        {
            var data = _despository.List(dto);
            //PageData<GuideDto> res = new PageData<GuideDto>
            //{
            //    TotalNum = data.TotalNum,
            //    TotalPageCount = data.TotalPageCount,
            //    Items = Mapper.Map<List<GuideDto>>(data.Items)
            //};
            var result = Mapper.Map <PageData <GuideDto> >(data);

            return(result);
        }
Ejemplo n.º 3
0
 public ActionResult <PageData <GuideDto> > List([FromBody] GuideListDto dto)
 { //执行
     return(_guide.List(dto));
 }