public IHttpActionResult AddProductBrand(ProductBrandEntity model) { try { var existe = context.ProductBrand.FirstOrDefault(x => x.ProductId == model.ProductId && x.BrandId == model.BrandId && x.Status == ConstantHelpers.ESTADO.ACTIVO); using (var ts = new TransactionScope()) { ProductBrand ProductBrand = new ProductBrand(); if (model.ProductBrandId.HasValue) { ProductBrand = context.ProductBrand.FirstOrDefault(x => x.ProductBrandId == model.ProductBrandId); } else { if (existe != null) { response.Data = "Marca producto ya registrado"; response.Error = true; response.Message = "Error"; return(Content(HttpStatusCode.Conflict, response)); } context.ProductBrand.Add(ProductBrand); ProductBrand.Status = ConstantHelpers.ESTADO.ACTIVO; } ProductBrand.BrandId = model.BrandId; ProductBrand.ProductId = model.ProductId; context.SaveChanges(); //CREAR STOCK PRODUCTO if (!model.ProductBrandId.HasValue) { StockProduct stockProduct = new StockProduct(); context.StockProduct.Add(stockProduct); stockProduct.Amount = 0; stockProduct.ProductBrandId = ProductBrand.ProductBrandId; stockProduct.Status = ConstantHelpers.ESTADO.ACTIVO; context.SaveChanges(); } ts.Complete(); } response.Data = "Product brand added"; response.Error = false; response.Message = "Success"; return(Ok(response)); } catch (Exception e) { return(Unauthorized()); } }
public ProductBrandEntity Update(ProductBrandEntity entity) { try { _productbrandRepository.Update(entity); return(entity); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return(null); } }
public bool Delete(ProductBrandEntity entity) { try { _productbrandRepository.Delete(entity); return(true); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return(false); } }
public HttpResponseMessage EditProduct(JObject obj) { dynamic json = obj; JObject JProduct = json.product; JObject JProductDetail = json.productDetail; var newProduct = JProduct.ToObject <ProductModel>(); var newProductDetail = JProductDetail.ToObject <ProductDetailModel>(); var oldProduct = _productService.GetProductById(newProduct.Id); var oldProductDetail = _productDetailService.GetProductDetailById(oldProduct.ProductDetail.Id); ClassifyEntity CE = _classifyService.GetClassifyById(newProduct.ClassifyId); ProductBrandEntity CBE = _productBrandService.GetProductBrandById(newProduct.ProductBrandId); //商品 oldProduct.Price = newProduct.Price; oldProduct.ProductBrand = CBE; oldProduct.Classify = CE; oldProduct.Productname = newProduct.Productname; oldProduct.Commission = newProduct.Commission; oldProduct.ContactPhone = newProduct.ContactPhone; oldProduct.Dealcommission = newProduct.Dealcommission; oldProduct.Productimg = newProduct.Productimg; oldProduct.Status = newProduct.Status; oldProduct.Recommend = newProduct.Recommend; oldProduct.Stockrule = newProduct.Stockrule; oldProduct.SubTitle = newProduct.SubTitle; oldProduct.Upduser = _workContent.CurrentUser.Id.ToString(); oldProduct.Updtime = DateTime.Now; oldProduct.RecCommission = newProduct.RecCommission; //商品详细 oldProductDetail.Productname = newProduct.Productname; oldProductDetail.Productdetail = newProductDetail.Productdetail; oldProductDetail.Productimg = newProductDetail.Productimg; oldProductDetail.Sericeinstruction = newProductDetail.Sericeinstruction; oldProductDetail.Productimg1 = newProductDetail.Productimg1; oldProductDetail.Productimg2 = newProductDetail.Productimg2; oldProductDetail.Productimg3 = newProductDetail.Productimg3; oldProductDetail.Productimg4 = newProductDetail.Productimg4; oldProductDetail.Updtime = DateTime.Now; oldProductDetail.Upduser = _workContent.CurrentUser.Id.ToString(); if (_productService.Update(oldProduct) != null && _productDetailService.Update(oldProductDetail) != null) { return(PageHelper.toJson(PageHelper.ReturnValue(true, "修改成功"))); } else { return(PageHelper.toJson(PageHelper.ReturnValue(false, "修改失败"))); } }
public HttpResponseMessage AddProductBrandParameter([FromBody] ProductBrandParameterModel productBrandParameterModel) { ProductBrandEntity pbe = _productBrandService.GetProductBrandById(productBrandParameterModel.ProductBrandId); var productPramater = pbe.ParameterEntities.Select(p => new { p.Parametername }).Select(pp => new { pp.Parametername }).ToList(); foreach (var i in productPramater) { if (i.Parametername == productBrandParameterModel.Parametername) { return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据已经存在,请重新编辑!"))); } } BrandParameterEntity bpe = new BrandParameterEntity() { Addtime = DateTime.Now, Adduser = productBrandParameterModel.Adduser, Updtime = DateTime.Now, Upduser = productBrandParameterModel.Upduser, Parametername = productBrandParameterModel.Parametername, Parametervaule = productBrandParameterModel.Parametervaule, ProductBrand = pbe }; try { _brandParameterService.Create(bpe); return(PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功!"))); } catch (Exception) { return(PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败!"))); } }
public HttpResponseMessage AddProductBrand([FromBody] ProductBrandModel productBrandModel) { Regex reg = new Regex(@"^[^ %@#!*~&',;=?$\x22]+$"); var m = reg.IsMatch(productBrandModel.Bname); if (!m) { return(PageHelper.toJson(PageHelper.ReturnValue(false, "存在非法字符!"))); } else { ProductBrandEntity pbe = new ProductBrandEntity() { Addtime = DateTime.Now, Adduser = _workContext.CurrentUser.Id.ToString(CultureInfo.InvariantCulture), Bimg = productBrandModel.Bimg, Bname = productBrandModel.Bname, Updtime = DateTime.Now, Upduser = _workContext.CurrentUser.Id.ToString(CultureInfo.InvariantCulture), SubTitle = productBrandModel.SubTitle, Content = productBrandModel.Content, AdTitle = productBrandModel.AdTitle, ClassId = productBrandModel.ClassId }; try { _productBrandService.Create(pbe); return(PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功!"))); } catch (Exception) { return(PageHelper.toJson(PageHelper.ReturnValue(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; //} }