public ProductEntity Update(ProductEntity entity) { try { _productRepository.Update(entity); return entity; } catch (Exception e) { _log.Error(e, "数据库操作出错"); return null; } }
public bool Delete(ProductEntity entity) { try { _productRepository.Delete(entity); return true; } catch (Exception e) { _log.Error(e, "数据库操作出错"); return false; } }
public HttpResponseMessage AddProduct([FromBody]JObject obj) { dynamic json = obj; JObject JProduct = json.product; JObject JProductDetail = json.productDetail; var product = JProduct.ToObject<ProductModel>(); var productDetail = JProductDetail.ToObject<ProductDetailModel>(); Regex reg = new Regex(@"^[^%@#!*~&',;=?$\x22]+$"); var m = reg.IsMatch(productDetail.Productname); if (!m) { return PageHelper.toJson(PageHelper.ReturnValue(false, "存在非法字符!")); } else { //先创建productDetail,跟据部分productDetail部分重叠信息创建product; ProductDetailEntity PDE = new ProductDetailEntity() { Id = 0, Productdetail = productDetail.Productdetail, Productimg = productDetail.Productimg, Productimg1 = productDetail.Productimg1, Productimg2 = productDetail.Productimg2, Productimg3 = productDetail.Productimg3, Productimg4 = productDetail.Productimg4, Productname = productDetail.Productname, Sericeinstruction = productDetail.Sericeinstruction, Ad1 = productDetail.Ad1, Addtime = DateTime.Now, //Adduser = productDetail.Adduser, Adduser = _workContent.CurrentUser.Id.ToString(), Updtime = DateTime.Now, //Upduser = productDetail.Upduser Upduser = _workContent.CurrentUser.Id.ToString() }; ProductDetailEntity PDE2 = _productDetailService.Create(PDE); ClassifyEntity CE = _classifyService.GetClassifyById(product.ClassifyId); ProductBrandEntity CBE = _productBrandService.GetProductBrandById(product.ProductBrandId); ProductEntity PE = new ProductEntity() { Bussnessid = product.Bussnessid, BussnessName = "yoopoon", Commission = product.Commission, RecCommission = product.RecCommission, Dealcommission = product.Dealcommission, Price = product.Price, Classify = CE, ProductBrand = CBE, ProductDetail = PDE2, Productimg = product.Productimg, Productname = PDE.Productname, Recommend = product.Recommend, Sort = product.Sort, Status = product.Status, Stockrule = product.Stockrule, SubTitle = product.SubTitle, ContactPhone = product.ContactPhone, Updtime = DateTime.Now, //Upduser = PDE.Upduser, Upduser = _workContent.CurrentUser.Id.ToString(), Addtime = DateTime.Now, //Adduser = PDE.Adduser Adduser = _workContent.CurrentUser.Id.ToString() }; var Product = _productService.Create(PE); if (Product != null) { return PageHelper.toJson(PageHelper.ReturnValue(true, "数据添加成功!", Product.Id)); } else { return PageHelper.toJson(PageHelper.ReturnValue(false, "数据添加失败!")); } } //try //{ // return _productService.Create(PE).Id; //} //catch (Exception 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 }); }