public IQueryable<ClassifyEntity> GetClassifysByCondition(ClassifySearchCondition condition) { var query = _classifyRepository.Table; try { if (condition.AddtimeBegin.HasValue) { query = query.Where(q => q.Addtime>= condition.AddtimeBegin.Value); } if (condition.AddtimeEnd.HasValue) { query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value); } if (condition.UpdtimeBegin.HasValue) { query = query.Where(q => q.Updtime>= condition.UpdtimeBegin.Value); } if (condition.UpdtimeEnd.HasValue) { query = query.Where(q => q.Updtime < condition.UpdtimeEnd.Value); } if (!string.IsNullOrEmpty(condition.Name)) { query = query.Where(q => q.Name.Contains(condition.Name)); } if (!string.IsNullOrEmpty(condition.Adduser)) { query = query.Where(q => q.Adduser.Contains(condition.Adduser)); } if (!string.IsNullOrEmpty(condition.Upduser)) { query = query.Where(q => q.Upduser.Contains(condition.Upduser)); } if (condition.Ids != null && condition.Ids.Any()) { query = query.Where(q => condition.Ids.Contains(q.Id)); } if (condition.Classifys != null && condition.Classifys.Any()) { query = query.Where(q => condition.Classifys.Contains(q.Classify)); } if (condition.Sorts != null && condition.Sorts.Any()) { query = query.Where(q => condition.Sorts.Contains(q.Sort)); } if(condition.OrderBy.HasValue) { switch (condition.OrderBy.Value) { case EnumClassifySearchOrderBy.OrderById: query = condition.IsDescending?query.OrderByDescending(q=>q.Id):query.OrderBy(q=>q.Id); break; } } else { query = query.OrderBy(q=>q.Id); } if (condition.Page.HasValue && condition.PageCount.HasValue) { query = query.Skip((condition.Page.Value - 1)*condition.PageCount.Value).Take(condition.PageCount.Value); } return query; } catch(Exception e) { _log.Error(e,"数据库操作出错"); return null; } }
public List<TreeJsonModel> GetJsonFromTreeModel(int nodeId) { ClassifySearchCondition csc = new ClassifySearchCondition() { OrderBy = EnumClassifySearchOrderBy.OrderById }; List<TreeJsonModel> datalist = new List<TreeJsonModel>(); List<ClassifyEntity> ceList = _classifyService.GetClassifysBySuperClassify(nodeId).ToList();//找出该级的子集; foreach (var ce in ceList) { TreeJsonModel TJM = new TreeJsonModel() { label = ce.Name, Id = ce.Id }; datalist.Add(TJM); TJM.children = GetJsonFromTreeModel(TJM.Id);//自迭代; } if (ceList.Count == 0)//若遍历到末端,则: { return null; } else { return datalist; } }
public int GetClassifyCount (ClassifySearchCondition condition) { var query = _classifyRepository.Table; try { if (condition.AddtimeBegin.HasValue) { query = query.Where(q => q.Addtime>= condition.AddtimeBegin.Value); } if (condition.AddtimeEnd.HasValue) { query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value); } if (condition.UpdtimeBegin.HasValue) { query = query.Where(q => q.Updtime>= condition.UpdtimeBegin.Value); } if (condition.UpdtimeEnd.HasValue) { query = query.Where(q => q.Updtime < condition.UpdtimeEnd.Value); } if (!string.IsNullOrEmpty(condition.Name)) { query = query.Where(q => q.Name.Contains(condition.Name)); } if (!string.IsNullOrEmpty(condition.Adduser)) { query = query.Where(q => q.Adduser.Contains(condition.Adduser)); } if (!string.IsNullOrEmpty(condition.Upduser)) { query = query.Where(q => q.Upduser.Contains(condition.Upduser)); } if (condition.Ids != null && condition.Ids.Any()) { query = query.Where(q => condition.Ids.Contains(q.Id)); } if (condition.Classifys != null && condition.Classifys.Any()) { query = query.Where(q => condition.Classifys.Contains(q.Classify)); } if (condition.Sorts != null && condition.Sorts.Any()) { query = query.Where(q => condition.Sorts.Contains(q.Sort)); } return query.Count(); } catch(Exception e) { _log.Error(e,"数据库操作出错"); return -1; } }
public List<TreeJsonModel> GetAllTree() { ClassifySearchCondition csc = new ClassifySearchCondition() { OrderBy = EnumClassifySearchOrderBy.OrderById }; List<ClassifyEntity> ceListBuffer = new List<ClassifyEntity>(); List<TreeJsonModel> treeJsonModelBuffer = new List<TreeJsonModel>(); List<ClassifyEntity> ceList = _classifyService.GetClassifysByCondition(csc).ToList(); foreach (var ce in ceList) { if (ce.Classify == null) { ceListBuffer.Add(ce);//查找第一级; } } foreach (var ce in ceListBuffer) { TreeJsonModel TJM = new TreeJsonModel() { label = ce.Name, Id = ce.Id }; treeJsonModelBuffer.Add(TJM); TJM.children = GetJsonFromTreeModel(TJM.Id); } return treeJsonModelBuffer; }
public HttpResponseMessage GetClassList() { ClassifySearchCondition csc = new ClassifySearchCondition() { OrderBy = EnumClassifySearchOrderBy.OrderById }; var classLsit = _classifyService.GetClassifysByCondition(csc).Select(p => new { p.Id, p.Name }).ToList(); return PageHelper.toJson(classLsit); }
public HttpResponseMessage GetAllClassify() { ClassifySearchCondition csc = new ClassifySearchCondition() { OrderBy = EnumClassifySearchOrderBy.OrderById }; return PageHelper.toJson(GetAllTree().ToList()); }
public HttpResponseMessage SearchBrand(string condition, int page, int pageCount,string className) { var con = new ClassifySearchCondition() { Name = className }; var classify= _classifyService.GetClassifysByCondition(con).FirstOrDefault(); ProductBrandSearchCondition bcon = new ProductBrandSearchCondition { Bname = condition, Page = page, PageCount = pageCount, OrderBy = EnumProductBrandSearchOrderBy.OrderByAddtime, IsDescending = true, Classify =classify }; var brandList = _productBrandService.GetProductBrandsByCondition(bcon).Select(a => new { a.Id, a.Bimg, a.Bname, a.SubTitle, a.Content, a.AdTitle, ProductPramater = a.ParameterEntities.Select(p => new { p.Parametername, p.Parametervaule }) }).ToList(); var count = _productBrandService.GetProductBrandCount(bcon); return PageHelper.toJson(new { List = brandList.Select(c => new { c.Id, c.Bimg, c.Bname, c.SubTitle, c.Content, c.AdTitle, ProductParamater = c.ProductPramater.ToDictionary(k => k.Parametername, v => v.Parametervaule) }), Count = count }); //return PageHelper.toJson(new {List=brandList,Count=count}); }
public HttpResponseMessage GetAllBrand(int page = 1, int pageSize = 10, string className = null, bool isDes = true, EnumProductBrandSearchOrderBy orderByAll = EnumProductBrandSearchOrderBy.OrderByAddtime) { var con=new ClassifySearchCondition() { Name = className }; var classname=_classifyService.GetClassifysByCondition(con).FirstOrDefault(); //参数className 不传值则默认查询所有品牌 if (string.IsNullOrEmpty(className)) { classname = null; } var sech = new ProductBrandSearchCondition { //=========================yangyue 2015/7/7 start===================================================== IsDescending = isDes, OrderBy = orderByAll, Classify=classname, //======================== end ==================================================================== Page = page, PageCount = pageSize }; // var list = _productBrandService.GetProductBrandsByCondition(sech).Select(a => new //{ // Page = page, // PageCount = pageSize, //}); //取出所有品牌 var list = _productBrandService.GetProductBrandsByCondition(sech).Select(a => new { a.Id, a.Bimg, a.Bname, a.SubTitle, a.Content, a.Addtime, a.AdTitle, ProductParamater = a.ParameterEntities.Select(p => new { p.Parametername, p.Parametervaule }) }).ToList().Select(b => new { b.Id, b.Bimg, b.Bname, b.SubTitle, b.Content, b.AdTitle, ProductParamater = b.ProductParamater.ToDictionary(k => k.Parametername, v => v.Parametervaule), b.Addtime }); var totalCount1 = _productBrandService.GetProductBrandCount(sech); return PageHelper.toJson(new { List = list, Condition = sech, totalCount = totalCount1 }); //var totalCount = _productBrandService.GetProductBrandCount(Brandcondition); //var BrandList = _productBrandService.GetProductBrandsByCondition(Brandcondition).Select(a => new //{ // a.Id, // a.Bimg, // a.Bname, // a.SubTitle, // a.Content, // ProductParamater = a.ParameterEntities.Select(p => new { p.Parametername, p.Parametervaule }) //}).ToList(); //return PageHelper.toJson(new { brandList = BrandList.Select(b => new { // b.Id, // b.Bimg, // b.Bname, // b.SubTitle, // b.Content, // ProductParamater=b.ProductParamater.ToDictionary(k=>k.Parametername,v=>v.Parametervaule) //}), totalCount = totalCount }); ////return PageHelper.toJson(_productBrandService.GetProductBrandsByCondition(PBSC).ToList()); }