public IQueryable<ProductBrandEntity> GetProductBrandsByCondition(ProductBrandSearchCondition condition) { var query = _productbrandRepository.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.Classify!=null) { query = query.Where(q => q.ClassId == condition.Classify.Id); } 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.Bname)) { query = query.Where(q => q.Bname.Contains(condition.Bname)); } if (!string.IsNullOrEmpty(condition.Bimg)) { query = query.Where(q => q.Bimg.Contains(condition.Bimg)); } 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.ProductBrand != null) { query = query.Where(q => q.Id == condition.ProductBrand); } if (condition.OrderBy.HasValue) { switch (condition.OrderBy.Value) { case EnumProductBrandSearchOrderBy.OrderById: query = condition.IsDescending ? query.OrderByDescending(q => q.Id) : query.OrderBy(q => q.Id); break; case EnumProductBrandSearchOrderBy.OrderByAddtime: query=condition.IsDescending ? query.OrderByDescending(q => q.Addtime) : query.OrderBy(q => q.Addtime); 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 int GetProductBrandCount(ProductBrandSearchCondition condition) { var query = _productbrandRepository.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.Classify != null) { query = query.Where(q => q.ClassId == condition.Classify.Id); } 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.Bname)) { query = query.Where(q => q.Bname.Contains(condition.Bname)); } if (condition.ProductBrand != null) { query = query.Where(q => q.Id == condition.ProductBrand); } if (!string.IsNullOrEmpty(condition.Bimg)) { query = query.Where(q => q.Bimg.Contains(condition.Bimg)); } 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)); } return query.Count(); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return -1; } }
public HttpResponseMessage GetOneBrand(int page = 1, int pageSize = 10) { var sech = new ProductBrandSearchCondition { Page = page, PageCount = pageSize, }; //取出所有品牌 var brandList = _productBrandService.GetProductBrandsByCondition(sech).Select(a => new { a.Id, a.Bimg, a.Bname }).ToList(); //通过品牌取出该品牌下的价格最低的一个商品 var product = new ProductEntity(); List<RecProdcut> listRecProdcut = new List<RecProdcut>(); foreach (var i in brandList) { product = GetProductByBrand(i.Id); if (product != null) { listRecProdcut.Add(new RecProdcut { Bimg = i.Bimg, BrandId = i.Id.ToString(), BrandName = i.Bname, Commition = product.Dealcommission.ToString(), HouseType = product.ProductParameter.FirstOrDefault(o => o.Parameter.Name == "户型") == null ? "" : product.ProductParameter.FirstOrDefault(o => o.Parameter.Name == "户型").ParameterValue.Parametervalue.ToString(), Price = product.Price.ToString(), ProductId = product.Id, SubTitle = product.SubTitle, Productname = product.Productname }); } } var totalCount1 = _productBrandService.GetProductBrandCount(sech); // return PageHelper.toJson(new { List = BrandList, Product = product, Condition = sech, totalCount = totalCount1 }); return PageHelper.toJson(new { List = listRecProdcut, Condition = sech, totalCount = totalCount1 }); }
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 GetBrandList() { ProductBrandSearchCondition brandcondition = new ProductBrandSearchCondition { IsDescending = true, OrderBy = EnumProductBrandSearchOrderBy.OrderById }; var brandList = _productBrandService.GetProductBrandsByCondition(brandcondition).Select(a => new { a.Id, a.Bname, }).ToList(); return PageHelper.toJson(brandList); }
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()); }