public IHttpActionResult PostProduct(Product product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ProductBLL.Add(product); try { Global.SaveChanges(); } catch (DbUpdateException) { if (ProductExists(product.code)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = product.code }, product)); }
public IHttpActionResult PostProduct(ProductDTO product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ProductDTO proRes = ProductBLL.Add(product); return(Ok(proRes)); }
public void AddTest() { T_Product model = new T_Product { Name = "aaaa", Manufactor = "qwe", Mobile = "12345678901", FK_Variety = Guid.Parse("012FA116-F518-4CF4-91B9-EF5200C3388A"), Region = "asd", Remark = "" }; _bll.Add(model); }
protected void btnSave_Click(object sender, EventArgs e) { if (txtProductName.Text == "") { txtProductName.Focus(); return; } PDTO.ProductName = txtProductName.Text.ToString(); PDTO.CategoryId = Convert.ToInt16(ddlCategory.SelectedValue); PDTO.UnitId = Convert.ToInt16(ddlUnit.SelectedValue); PDTO.CompId = Convert.ToInt16(ddlCompany.SelectedValue); PDTO.CenterReorderValue = Convert.ToInt32(txtCenterReorderQuantity.Text); PDTO.CreateDate = System.DateTime.Now; PDTO.CreateBy = "tarun"; if (btnSave.Text == "Save") { PBLL.Add(PDTO); pagingLoal(); clearCntrol(); // barcode var data = PBLL.GetProduct(0, "", 0, 0, 0); string productid = data.First().ProductId.ToString(); txtProductBarCode.Text = productid; if (txtProductBarCode.Text != "") { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "key", "launchModal();", true); } } else { PDTO.ProductId = Convert.ToInt32(HFUID.Value); PBLL.Edit(PDTO); btnSave.Text = "Save"; pagingLoal(); clearCntrol(); // barcode // for barcode popup string Empid = Convert.ToString(HFUID.Value); txtProductBarCode.Text = Empid; if (txtProductBarCode.Text != "") { ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "key", "launchModal();", true); } } }
public ActionResult Add(Product product) { if (ModelState.IsValid) { if (_productBll.Add(product)) { ViewBag.SuccesMsg = "Saved"; } else { ViewBag.FailedMsg = "Failed"; } } else { ViewBag.FailedMsg = "Validation Failed"; } return(View()); }
protected void btnSave_Click(object sender, EventArgs e) { try { /* * if (txtProductName.Text == "") * { * txtProductName.Focus(); * return; * } */ // PDTO.ProductName = txtProductName.Text.ToString(); PDTO.ProductPurchasePrice = Convert.ToDouble(txtPurchasePrice.Text); PDTO.CategoryId = Convert.ToInt16(ddlCategory.SelectedValue); // PDTO.UnitId = Convert.ToInt16(ddlUnit.SelectedValue); PDTO.CompId = Convert.ToInt16(ddlCompany.SelectedValue); PDTO.CenterReorderValue = Convert.ToInt32(txtCenterReorderQuantity.Text); PDTO.CreateDate = System.DateTime.Now; PDTO.ProductSalePrice = Convert.ToDouble(txtSalePrice.Text); PDTO.ProductOffSalePrice = Convert.ToDouble(txtOffSale.Text); PDTO.CreateBy = HttpContext.Current.User.Identity.Name; PDTO.ProductReOrderStatus = 0; if (btnSave.Text == "Save") { var checkCount = PBLL.CheckProductCodeExits(int.Parse(ddlCompany.SelectedValue), "", int.Parse(ddlCategory.SelectedValue)); if (checkCount.Count() > 0) { Show("Product already Exist in this company "); return; } else { PBLL.Add(PDTO); Show("Sucessfully Created!"); pagingLoal(); clearCntrol(); // barcode /* * var data = PBLL.GetProduct(0, "", 0, 0, 0); * string productid = data.First().ProductId.ToString(); * txtProductBarCode.Text = productid; * if (txtProductBarCode.Text != "") * ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "key", "launchModal();", true); * */ } } else { PDTO.ProductId = Convert.ToInt32(HFUID.Value); //var checkUpCount = PBLL.CheckProductCodeExits(int.Parse(ddlCompany.SelectedValue), txtProductName.Text,int.Parse(HFUID.Value)); //if (checkUpCount.Count()> 0) //{ // Show("Product Code :" + txtProductName.Text + " already Used By Another Product in this company "); // return; //}else{ PBLL.Edit(PDTO); btnSave.Text = "Save"; Show("Sucessfully Updated!"); pagingLoal(); clearCntrol(); // barcode // for barcode popup /* * string Empid = Convert.ToString(HFUID.Value); * txtProductBarCode.Text = Empid; * if (txtProductBarCode.Text != "") * ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "key", "launchModal();", true); * */ //} } } catch (Exception ex) { Show(ex.Message); } }
static void AddSamepleProduct() { ProductBLL.Add("D003", "Coke", 20, "noimage.jpg"); }
/// <summary> /// 保存草稿 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DraftButton_Click(object sender, EventArgs e) { int id = RequestHelper.GetQueryString <int>("ID"); ProductInfo product = new ProductInfo(); if (id > 0) { product = ProductBLL.Read(id); } product.Name = Name.Text; product.Spelling = ChineseCharacterHelper.GetFirstLetter(Name.Text); product.Color = RequestHelper.GetForm <string>("ProductColor"); product.FontStyle = FontStyle.Text; product.ProductNumber = ProductNumber.Text; //product.ClassId = ProductClass.ClassID; if (!string.IsNullOrEmpty(RequestHelper.GetQueryString <string>("classId"))) { product.ClassId = RequestHelper.GetQueryString <string>("classId"); } product.Keywords = Keywords.Text; product.BrandId = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$BrandID"); product.MarketPrice = Convert.ToDecimal(MarketPrice.Text); product.SendPoint = Convert.ToInt32(SendPoint.Text); product.Photo = Photo.Text; product.Summary = Summary.Text; product.Introduction1 = Introduction.Value; product.Weight = Convert.ToDecimal(Weight.Text); product.IsSpecial = Convert.ToInt32(IsSpecial.Checked); product.IsNew = Convert.ToInt32(IsNew.Checked); product.IsHot = Convert.ToInt32(IsHot.Checked); product.IsSale = 2;//草稿状态 product.IsTop = Convert.ToInt32(IsTop.Checked); product.Remark = Remark.Value; product.Accessory = RequestHelper.GetForm <string>("RelationAccessoryID"); product.RelationProduct = RequestHelper.GetForm <string>("RelationProductID"); product.RelationArticle = RequestHelper.GetForm <string>("RelationArticleID"); product.AllowComment = Convert.ToInt32(AllowComment.Checked); product.TotalStorageCount = Convert.ToInt32(TotalStorageCount.Text); if (TotalStorageCount.ReadOnly) { product.TotalStorageCount = Convert.ToInt32(HidTotalStorageCount.Value); } product.LowerCount = Convert.ToInt32(LowerCount.Text.Trim()); product.UpperCount = 0; product.StandardType = Convert.ToInt32(RequestHelper.GetForm <string>("StandardType")); product.AddDate = RequestHelper.DateNow; product.OrderId = Convert.ToInt32(OrderID.Text.Trim()); product.SalePrice = Convert.ToDecimal(SalePrice.Text); product.Unit = Units.Text; product.Introduction1_Mobile = Introduction_Mobile.Value; product.SubTitle = Sub_Title.Text; string alertMessage = ShopLanguage.ReadLanguage("AddOK"); CheckAdminPower("AddProduct", PowerCheckType.Single); int pid = ProductBLL.Add(product); AddProductPhoto(pid); AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("Product"), pid); HanderAttribute(product); //HanderMemberPrice(product.ID); HanderProductStandard(product); ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl); }
/// <summary> /// 提交按钮点击方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SubmitButton_Click(object sender, EventArgs e) { int id = RequestHelper.GetQueryString <int>("ID"); ProductInfo product = new ProductInfo(); if (id > 0) { product = ProductBLL.Read(id); } product.YejiRatio = YejiRatio.Text; product.Name = Name.Text; product.SellPoint = SellPoint.Text; product.Spelling = ChineseCharacterHelper.GetFirstLetter(Name.Text); product.Color = RequestHelper.GetForm <string>("ProductColor"); product.FontStyle = FontStyle.Text; product.ProductNumber = ProductNumber.Text; //product.ClassId = ProductClass.ClassID; if (!string.IsNullOrEmpty(RequestHelper.GetQueryString <string>("classId"))) { product.ClassId = RequestHelper.GetQueryString <string>("classId"); } product.Keywords = Keywords.Text; product.BrandId = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$BrandID"); product.MarketPrice = Convert.ToDecimal(MarketPrice.Text); product.SendPoint = Convert.ToInt32(SendPoint.Text); product.Photo = Photo.Text; product.Summary = Summary.Text; product.Introduction1 = Introduction.Value; product.Weight = Convert.ToDecimal(Weight.Text); product.IsSpecial = Convert.ToInt32(IsSpecial.Checked); product.IsNew = Convert.ToInt32(IsNew.Checked); product.IsHot = Convert.ToInt32(IsHot.Checked); product.IsSale = Convert.ToInt32(IsSale.Checked); product.IsTop = Convert.ToInt32(IsTop.Checked); //保存时如果售后服务为空则自动获取所属分类的售后服务并保存 product.Remark = string.IsNullOrEmpty(StringHelper.KillHTML(Remark.Value)) ? GetProductClassRemark(product.ClassId) : Remark.Value; product.Accessory = RequestHelper.GetForm <string>("RelationAccessoryID"); product.RelationProduct = RequestHelper.GetForm <string>("RelationProductID"); product.RelationArticle = RequestHelper.GetForm <string>("RelationArticleID"); product.AllowComment = Convert.ToInt32(AllowComment.Checked); product.TotalStorageCount = Convert.ToInt32(TotalStorageCount.Text); if (TotalStorageCount.ReadOnly) { product.TotalStorageCount = Convert.ToInt32(HidTotalStorageCount.Value); } product.LowerCount = Convert.ToInt32(LowerCount.Text.Trim()); product.UpperCount = 0; product.StandardType = Convert.ToInt32(RequestHelper.GetForm <string>("StandardType")); product.AddDate = RequestHelper.DateNow; product.OrderId = Convert.ToInt32(OrderID.Text.Trim()); product.SalePrice = Convert.ToDecimal(SalePrice.Text); product.Unit = Units.Text; product.Introduction1_Mobile = Introduction_Mobile.Value; product.SubTitle = Sub_Title.Text; #region 商品开团 //是否开启开团 product.OpenGroup = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$OpenGroup") <= 0 ? 0 : 1; decimal _groupPrice = 0; decimal.TryParse(GroupPrice.Text.Trim(), out _groupPrice); product.GroupPrice = _groupPrice < 0 ? 0 : _groupPrice; int _groupQuantity = 0; int.TryParse(GroupQuantity.Text.Trim(), out _groupQuantity); product.GroupQuantity = _groupQuantity < 0 ? 0 : _groupQuantity; product.GroupPhoto = GroupPhoto.Text; #endregion //是否启用不限库存 product.UnlimitedStorage = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$UnlimitedStorage"); #region 虚拟库存 //是否启用虚拟销量 product.UseVirtualOrder = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$UseVirtualOrder") <= 0 ? 0 : 1; //虚拟销量数 product.VirtualOrderCount = Convert.ToInt32(VirtualOrderCount.Text) <= 0 ? 0 : Convert.ToInt32(VirtualOrderCount.Text); #endregion string alertMessage = ShopLanguage.ReadLanguage("AddOK"); if (id <= 0) { CheckAdminPower("AddProduct", PowerCheckType.Single); int pid = ProductBLL.Add(product); AddProductPhoto(pid); #region 添加时生成手机网站二维码 //string ewmName = string.Empty;//二维码路径 //CreateQRcode("http://" + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.Port > 0 ? ":" + HttpContext.Current.Request.Url.Port : "") + "/mobile/ProductDetail-i" + pid + ".html", "pro_" + pid.ToString(), ref ewmName); //Dictionary<string, object> dict = new Dictionary<string, object>(); //dict.Add("[Qrcode]", ewmName); //ProductBLL.UpdatePart("[Product]", dict, pid); #endregion #region 添加时生成小程序商品推广码(扫码进入小程序商品详情页) string product_miniProramCode = string.Empty; CreateMiniProgramCode(pid, ref product_miniProramCode, product.Qrcode); Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("[Qrcode]", product_miniProramCode); ProductBLL.UpdatePart("[Product]", dict, pid); #endregion AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("Product"), pid); } else { CheckAdminPower("UpdateProduct", PowerCheckType.Single); #region 添加时生成小程序商品推广码(扫码进入小程序商品详情页) string product_miniProramCode = string.Empty; CreateMiniProgramCode(id, ref product_miniProramCode, product.Qrcode); product.Qrcode = product_miniProramCode; #endregion ProductBLL.Update(product); AdminLogBLL.Add(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("Product"), product.Id); alertMessage = ShopLanguage.ReadLanguage("UpdateOK"); } HanderAttribute(product); //HanderMemberPrice(product.ID); HanderProductStandard(product); ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl); }
/// <summary> /// 提交按钮点击方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SubmitButton_Click(object sender, EventArgs e) { int id = RequestHelper.GetQueryString <int>("ID"); ProductInfo product = new ProductInfo(); //if (id > 0) product = ProductBLL.Read(id); product.Name = Name.Text; product.SellPoint = SellPoint.Text; product.Spelling = ChineseCharacterHelper.GetFirstLetter(Name.Text); product.Color = RequestHelper.GetForm <string>("ProductColor"); product.FontStyle = FontStyle.Text; product.ProductNumber = ProductNumber.Text; //product.ClassId = ProductClass.ClassID; product.ClassId = string.IsNullOrEmpty(RequestHelper.GetQueryString <string>("classId")) ? ProductBLL.Read(id).ClassId : RequestHelper.GetQueryString <string>("classId"); product.Keywords = Keywords.Text; product.BrandId = RequestHelper.GetForm <int>("ctl00$ContentPlaceHolder$BrandID"); product.MarketPrice = Convert.ToDecimal(MarketPrice.Text); product.SendPoint = Convert.ToInt32(SendPoint.Text); product.Photo = Photo.Text; product.Summary = Summary.Text; product.Introduction1 = Introduction.Value; product.Weight = Convert.ToDecimal(Weight.Text); product.IsSpecial = Convert.ToInt32(IsSpecial.Checked); product.IsNew = Convert.ToInt32(IsNew.Checked); product.IsHot = Convert.ToInt32(IsHot.Checked); product.IsSale = Convert.ToInt32(IsSale.Checked); product.IsTop = Convert.ToInt32(IsTop.Checked); //保存时如果售后服务为空则自动获取所属分类的售后服务并保存 product.Remark = string.IsNullOrEmpty(StringHelper.KillHTML(Remark.Value)) ? GetProductClassRemark(product.ClassId) : Remark.Value; product.Accessory = RequestHelper.GetForm <string>("RelationAccessoryID"); product.RelationProduct = RequestHelper.GetForm <string>("RelationProductID"); product.RelationArticle = RequestHelper.GetForm <string>("RelationArticleID"); product.AllowComment = Convert.ToInt32(AllowComment.Checked); product.TotalStorageCount = Convert.ToInt32(TotalStorageCount.Text); if (TotalStorageCount.ReadOnly) { product.TotalStorageCount = Convert.ToInt32(HidTotalStorageCount.Value); } product.LowerCount = 0; product.UpperCount = 0; product.StandardType = Convert.ToInt32(RequestHelper.GetForm <string>("StandardType")); product.AddDate = RequestHelper.DateNow; product.OrderId = Convert.ToInt32(OrderID.Text.Trim()); product.SalePrice = Convert.ToDecimal(SalePrice.Text); product.Unit = Units.Text; product.Introduction1_Mobile = Introduction_Mobile.Value; product.SubTitle = Sub_Title.Text; string alertMessage = ShopLanguage.ReadLanguage("AddOK"); CheckAdminPower("AddProduct", PowerCheckType.Single); int pid = ProductBLL.Add(product); AddProductPhoto(pid); #region 添加时生成二维码 string ewmName = string.Empty;//二维码路径 CreateQRcode("http://" + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.Port > 0 ? ":" + HttpContext.Current.Request.Url.Port : "") + "/mobile/ProductDetail-i" + pid + ".html", "pro_" + pid.ToString(), ref ewmName); ProductInfo tmpProduct = ProductBLL.Read(pid); tmpProduct.Qrcode = ewmName; ProductBLL.Update(tmpProduct); #endregion AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("Product"), pid); HanderAttribute(product); HanderProductStandard(product); ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl); }
protected void ImportProducts(object sender, EventArgs e) { string categoryId = ProductClass.ClassID; int saleStatus = Convert.ToInt32(IsSale.SelectedValue); string selectedValue = dropFiles.SelectedValue; selectedValue = Path.Combine(_dataPath, selectedValue); if (!File.Exists(selectedValue)) { ScriptHelper.Alert("选择的数据包文件有问题!"); } else { PrepareDataFiles(new object[] { selectedValue }); string path = Path.Combine(_dataPath, Path.GetFileNameWithoutExtension(selectedValue)); DataTable productData = (DataTable)ProductBLL.ParseProductData(new object[] { path })[0]; if ((productData != null) && (productData.Rows.Count > 0)) { foreach (DataRow row in productData.Rows) { ProductInfo product = new ProductInfo { ClassId = categoryId, Name = (string)row["ProductName"], ProductNumber = (string)row["SKU"], BrandId = 0 }; if (row["Description"] != DBNull.Value) { product.Introduction1 = (string)row["Description"]; } product.AddDate = DateTime.Now; product.IsSale = saleStatus; product.MarketPrice = (decimal)row["SalePrice"]; product.TotalStorageCount = (int)row["Stock"]; product.Spelling = ChineseCharacterHelper.GetFirstLetter((string)row["ProductName"]); product.SendPoint = 0; product.Weight = 0; product.IsSpecial = 0; product.IsNew = 0; product.IsHot = 0; if (row["Has_ShowCase"] != DBNull.Value) { product.IsTop = Convert.ToInt32(row["Has_ShowCase"]); } product.AllowComment = 0; product.LowerCount = 0; product.UpperCount = 0; product.StandardType = 0; product.AddDate = RequestHelper.DateNow; product.OrderId = 0; product.SalePrice = (decimal)row["SalePrice"]; if (row["ImageUrl1"] != DBNull.Value) { product.Photo = (string)row["ImageUrl1"]; } int proID = ProductBLL.Add(product); #region 生成缩略图和产品相册图 if (!(string.IsNullOrEmpty(product.Photo) || (product.Photo.Length <= 0))) { UploadImage(product.Photo, PhotoType.Product); } if (row["ImageUrl2"] != DBNull.Value) { ProductPhotoInfo tempPhoto = new ProductPhotoInfo() { ProductId = proID, Name = "ImageUrl2", ImageUrl = (string)row["ImageUrl2"], AddDate = DateTime.Now }; ProductPhotoBLL.Add(tempPhoto); UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto); } if (row["ImageUrl3"] != DBNull.Value) { ProductPhotoInfo tempPhoto = new ProductPhotoInfo() { ProductId = proID, Name = "ImageUrl3", ImageUrl = (string)row["ImageUrl3"], AddDate = DateTime.Now }; ProductPhotoBLL.Add(tempPhoto); UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto); } if (row["ImageUrl4"] != DBNull.Value) { ProductPhotoInfo tempPhoto = new ProductPhotoInfo() { ProductId = proID, Name = "ImageUrl4", ImageUrl = (string)row["ImageUrl4"], AddDate = DateTime.Now }; ProductPhotoBLL.Add(tempPhoto); UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto); } if (row["ImageUrl5"] != DBNull.Value) { ProductPhotoInfo tempPhoto = new ProductPhotoInfo() { ProductId = proID, Name = "ImageUrl5", ImageUrl = (string)row["ImageUrl5"], AddDate = DateTime.Now }; ProductPhotoBLL.Add(tempPhoto); UploadImage(tempPhoto.ImageUrl, PhotoType.ProductPhoto); } #endregion } File.Delete(selectedValue); Directory.Delete(path, true); BindFiles(); ScriptHelper.Alert("此次商品批量导入操作已成功!", RequestHelper.RawUrl); } } }
public int Post([FromBody] Product parameter) { ProductBLL bll = new ProductBLL(); return(bll.Add(parameter)); }