示例#1
0
        public JsonResult LoadData(string companyName, int?countryId, int?stateId, int?cityId, GridPager pager)
        {
            List <AgentViewModel> agentList = new AgentBLL().GetAgentPersonPager(companyName, countryId, stateId, cityId, ref pager);

            if (agentList == null || agentList.Count <= 0)
            {
                return(Json(new List <AgentViewModel>().ToGridJson(pager)));
            }

            var areaBll     = new AreaBLL();
            var countryIds  = agentList.Select(t => t.CountryId).ToList();
            var countryList = areaBll.GetCountrysByIds(countryIds);
            var stateList   = areaBll.GetStatesByCountryIds(countryIds);
            var stateIds    = stateList.Select(t => t.Id).ToList();
            var cityList    = areaBll.GetCitysByStateIds(stateIds);

            var obj = agentList.ToGridJson(pager, r =>
                                           new
            {
                id   = r.Id,
                cell = new
                {
                    Id          = r.Id,
                    AgentCode   = r.AgentCode,
                    CompanyName = r.CompanyName,
                    CountryName = countryList.Where(t => t.Id == r.CountryId).Select(t => t.Name).FirstOrDefault(),
                    StateName   = stateList.Where(t => t.Id == r.StateId).Select(t => t.Name).FirstOrDefault(),
                    CityName    = cityList.Where(t => t.Id == r.CityId).Select(t => t.Name).FirstOrDefault(),
                    ContactName = r.ContactName,
                    ContactWay  = r.ContactWay,
                    SaleName    = r.SaleName,
                    CreateTime  = r.CreateTime.ToString("yyyy-MM-dd")
                }
            });

            return(Json(obj));
        }