Example #1
0
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pageParam"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public async Task <Page <AgentDto> > GetPage(AgentOption option)
        {
            var sql = Sql.Builder;

            //   sql.Append("where 1<>1 or id<@id",new { id= 2072 });
            if (!string.IsNullOrWhiteSpace(option.Name))
            {
                sql = sql.Where("`Name` like @Name", new { Name = "%" + option.Name.Trim() + "%" });
            }
            if (!string.IsNullOrWhiteSpace(option.ContactNumber))
            {
                sql = sql.Where("`ContactNumber`=@ContactNumber", new { ContactNumber = option.ContactNumber.Trim() });
            }
            //if (option.State.HasValue)
            //{
            //    sql = sql.Where("`State`=@State", new { State = option.State.Value });
            //}

            List <AgentDto> data  = new List <AgentDto>();
            int             total = await _agentRep.RecordCountAsync(sql.SQL, sql.Arguments);

            if (total > 0)
            {
                List <Agent> lists = (await _agentRep.GetListPagedAsync <Agent>(option.PageIndex, option.Limit, sql.SQL, option.OrderBy, sql.Arguments)).ToList();
                data = MapperHelper.MapList <Agent, AgentDto>(lists);
            }
            return(new Page <AgentDto>(total, data));
        }
Example #2
0
        // GET: /<controller>/
        public async Task <IActionResult> Index(AgentOption option)
        {
            if (Request.IsAjaxRequest())
            {
                var result = await _agentApp.GetPage(option);

                return(Json(result));
            }

            return(View());
        }