private List<LinkGroup> GetSearch(QueryTerm queryTerm) { List<LinkGroup> result = new List<LinkGroup>(); Dictionary<string, string> cacheDic = new Dictionary<string, string>(); cacheDic.Add(CacheService.ServiceName, "ListController"); cacheDic.Add(CacheService.ServiceMethod, "GetSearch"); cacheDic.Add("City", queryTerm.City.ToString()); cacheDic.Add("MediaCode", queryTerm.MediaCode.ToString()); cacheDic.Add("FormatCode", queryTerm.FormatCode.ToString()); cacheDic.Add("OwnerCode", queryTerm.OwnerCode.ToString()); cacheDic.Add("PeriodCode", queryTerm.PeriodCode.ToString()); if (CacheService.Exists(cacheDic)) { result = CacheService.Get<List<LinkGroup>>(cacheDic); return result; } #region CityGroup if (queryTerm.City != 0) { var city = CityCateService.Find(queryTerm.City); var prevCityGroup = new List<LinkGroup>(); GetPrevCityGroup(prevCityGroup, city, queryTerm); prevCityGroup.Reverse(); result.AddRange(prevCityGroup); GetNextCityGroup(result, city, queryTerm); } else { var city = CityCateService.Find(queryTerm.Province); GetNextCityGroup(result, city, queryTerm); } #endregion #region MediaCode if (queryTerm.MediaCode != 0) { var media = MediaCateService.Find(queryTerm.MediaCode); var prevMediaGroup = new List<LinkGroup>(); GetPrevMediaGroup(prevMediaGroup, media, queryTerm); prevMediaGroup.Reverse(); result.AddRange(prevMediaGroup); GetNextMediaGroup(result, media, queryTerm, false); } else { GetNextMediaGroup(result, null, queryTerm, true); } #endregion #region FormatCode LinkGroup formatGroup = new LinkGroup() { Group = new LinkItem() { Name = "媒体形式", Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = 0, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; formatGroup.Items = FormatCateService.GetALL().Where(x => x.PID.Equals(null)).ToList().Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = queryTerm.MediaCode, formatcode = x.ID, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }), Selected = queryTerm.FormatCode == x.ID }).ToList(); result.Add(formatGroup); #endregion #region OwnerCode //LinkGroup ownerGroup = new LinkGroup() //{ // Group = new LinkItem() // { // Name = "代理类型", // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = 0, // periodcode = queryTerm.PeriodCode, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }) // } //}; //ownerGroup.Items = OwnerCateService.GetALL().Where(x => x.PID.Equals(null)).ToList().Select(x => new LinkItem() //{ // ID = x.ID, // Name = x.CateName, // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = x.ID, // periodcode = queryTerm.PeriodCode, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }), // Selected = queryTerm.OwnerCode == x.ID //}).ToList(); //result.Add(ownerGroup); #endregion #region PeriodCode //LinkGroup periodGroup = new LinkGroup() //{ // Group = new LinkItem() // { // Name = "最短投放周期", // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = queryTerm.OwnerCode, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }) // } //}; //periodGroup.Items = PeriodCateService.GetALL().Where(x => x.PID.Equals(null)).ToList().Select(x => new LinkItem() //{ // ID = x.ID, // Name = x.CateName, // Url = Url.Action("index", new // { // province = queryTerm.Province, // city = queryTerm.City, // mediacode = queryTerm.MediaCode, // formatcode = queryTerm.FormatCode, // ownercode = queryTerm.OwnerCode, // periodcode = x.ID, // authstatus = queryTerm.AuthStatus, // deadline = queryTerm.DeadLine, // price = queryTerm.Price, // order = queryTerm.Order, // descending = queryTerm.Descending, // page = 1 // }), // Selected = queryTerm.PeriodCode == x.ID //}).ToList(); //result.Add(periodGroup); #endregion CacheService.Add<List<LinkGroup>>(result, cacheDic, 180); return result; }
private void GetPrevCityGroup(List<LinkGroup> result, CityCate city, QueryTerm queryTerm) { var pCity = CityCateService.GetALL().Single(x => x.ID == city.PID); LinkGroup cityGroup = new LinkGroup() { Group = new LinkItem() { Name = !pCity.PID.HasValue ? "城市" : pCity.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = !pCity.PID.HasValue ? 0 : pCity.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var cityList = CityCateService.GetALL() .Where(x => x.PID == pCity.ID).ToList(); var citySelectList = cityList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = x.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); if (citySelectList.Any(x => x.ID == city.ID)) { citySelectList.Single(x => x.ID == city.ID).Selected = true; } cityGroup.Items = citySelectList; result.Add(cityGroup); if (pCity.PID.HasValue) { GetPrevCityGroup(result, pCity, queryTerm); } }
private void GetPrevMediaGroup(List<LinkGroup> result, MediaCate media, QueryTerm queryTerm) { if (media.PID.HasValue) { var pMedia = MediaCateService.GetALL().Single(x => x.ID == media.PID); LinkGroup mediaGroup = new LinkGroup() { Group = new LinkItem() { Name = pMedia.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = pMedia.ID, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var mediaList = MediaCateService.GetALL() .Where(x => x.PID == pMedia.ID).ToList(); var mediaSelectList = mediaList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = x.ID, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); if (mediaSelectList.Any(x => x.ID == media.ID)) { mediaSelectList.Single(x => x.ID == media.ID).Selected = true; } mediaGroup.Items = mediaSelectList; result.Add(mediaGroup); GetPrevMediaGroup(result, pMedia, queryTerm); } else { LinkGroup mediaGroup = new LinkGroup() { Group = new LinkItem() { Name = "媒体分类", Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = 0, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var mediaList = MediaCateService.GetALL() .Where(x => x.PID.Equals(null)).ToList(); var mediaSelectList = mediaList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = queryTerm.City, mediacode = x.ID, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); if (mediaSelectList.Any(x => x.ID == media.ID)) { mediaSelectList.Single(x => x.ID == media.ID).Selected = true; } mediaGroup.Items = mediaSelectList; result.Add(mediaGroup); } }
private void GetNextCityGroup(List<LinkGroup> result, CityCate city, QueryTerm queryTerm) { if (CityCateService.GetALL().Any(x => x.PID == city.ID)) { LinkGroup cityGroup = new LinkGroup() { Group = new LinkItem() { Name = city.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = city.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) } }; var cityList = CityCateService.GetALL() .Where(x => x.PID == city.ID).ToList(); var citySelectList = cityList.Select(x => new LinkItem() { ID = x.ID, Name = x.CateName, Url = Url.Action("index", new { province = queryTerm.Province, city = x.ID, mediacode = queryTerm.MediaCode, formatcode = queryTerm.FormatCode, ownercode = queryTerm.OwnerCode, periodcode = queryTerm.PeriodCode, authstatus = queryTerm.AuthStatus, deadline = queryTerm.DeadLine, price = queryTerm.Price, order = queryTerm.Order, descending = queryTerm.Descending, page = 1 }) }).ToList(); cityGroup.Items = citySelectList; result.Add(cityGroup); } }