示例#1
0
        public async Task <BaseResponse> GetPageWarnCodeAsync(WarnCodePageRequest req)
        {
            Expression <Func <WarnCodeModel, bool> > predicate;

            if (req.warnTypeId == 0)
            {
                predicate = a => true;
            }
            else
            {
                predicate = a => a.WarnTypeId == req.warnTypeId;
            }
            var wc = _warnCode.FindWithWarnType(predicate);

            if (!string.IsNullOrWhiteSpace(req.Search))
            {
                wc = wc.Where(a => a.Code.Contains(req.Search));
            }
            int    count           = wc.Count();
            string OrderExpression = "";

            if (string.IsNullOrEmpty(req.OrderBy))
            {
                OrderExpression = "Code Asc";
            }
            else
            {
                OrderExpression = string.Format("{0} {1}", req.OrderBy, req.OrderType);
            }
            var data = await wc.OrderBy(OrderExpression).Skip((req.PageNo - 1) * req.PageSize).Take(req.PageSize).ToListAsync();

            var          dto = _mapper.Map <IEnumerable <WarnCodeDto> >(data);
            BaseResponse br  = new BasePageResponse <IEnumerable <WarnCodeDto> >()
            {
                Count       = count,
                CurrentPage = req.PageNo,
                PageSize    = req.PageSize,
                Success     = true,
                Message     = "获取数据成功",
                Data        = dto,
                TotalPage   = (int)Math.Ceiling((decimal)count / req.PageSize)
            };

            return(br);
        }
示例#2
0
        public async Task <ActionResult <BaseResponse> > GetWarnCode([FromQuery] WarnCodePageRequest req)
        {
            var rm = await _wcs.GetPageWarnCodeAsync(req);

            return(rm);
        }