public ActionResult Delete(int ID) { if (Session["role"] == null || (int)Session["role"] < Editor) { return(Redirect("/CMS/Product")); } ProductsTable produkt = pf.Get(ID); if (produkt.Image != null) { string imagePath = Request.PhysicalApplicationPath + "/Images/Products/" + produkt.Image; if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } } pf.Delete(ID); return(Redirect("/CMS/Product")); }
public ActionResult ShowProduct(int id = 0) { if (id > 0) { ProductVM vm = new ProductVM(); vm.Product = productFactory.Get(id); vm.Images = imageFactory.GetBy("ProductID", id); vm.Category = categoryFactory.Get(vm.Product.CategoryID); List <CommentVM> comments = new List <CommentVM>(); foreach (Comment comment in commentFactory.GetBy("ProductID", id)) { CommentVM cmv = new CommentVM(); cmv.Comment = comment; cmv.User = userFactory.Get(comment.UserID); comments.Add(cmv); } comments = comments.OrderBy(x => DateTime.Parse(x.Comment.Date)).ToList(); comments.Reverse(); ViewBag.Comments = comments; return(View(vm)); } else { return(RedirectToAction("Products")); } }
private void FillMarketCategory(ProductFactory productFactory, Enum productType) { foreach (Enum type in Enum.GetValues(productType.GetType())) { IBuyable ingredient = productFactory.Get(type); this.market.AddProduct(ingredient); } }
public ActionResult EditProduct(int id = 0) { if (id == 0) { return(RedirectToAction("Products")); } ViewBag.Categories = categoryFactory.GetAll(); List <Image> images = new List <Image>(); images.AddRange(imageFactory.GetBy("ProductID", 0)); images.AddRange(imageFactory.GetBy("ProductID", id)); ViewBag.Images = images; Product p = productFactory.Get(id); return(View(p)); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { int id = HYRequest.GetQueryInt("id", 0); if (id == 0) { Response.Redirect("index.aspx"); } this.productinfo = ProductFactory.Get(id); } }
private void LoadProductInfo() { if (this.Action == "edit") { int productid = HYRequest.GetQueryInt("productid", 0); ProductModel info = ProductFactory.Get(productid); this.txtincludepicpath.Text = info.includepicpath; this.txtprice.Text = info.price.ToString(); this.txtitemprice.Text = info.itemprice; this.txtproductname.Text = info.productname; this.txtsalecount.Text = info.salecount.ToString(); this.txtproductcount.Text = info.productcount.ToString(); //this.txtspecification.Text = info.specification; this.chkiscommend.Checked = info.iscommend == 1 ? true : false; this.editorcontent.Value = info.specification; try { this.rblproductcode.Items.FindByValue(info.productcode.ToString()).Selected = true; this.ddlProductCategory.Items.FindByValue(info.categoryid.ToString()).Selected = true; } catch { } if (info.productpics.Length > 5) { string[] picarr = info.productpics.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); DataTable dt = new DataTable(); dt.Columns.Add("picsrc", typeof(System.String)); foreach (string pic in picarr) { DataRow dr = dt.NewRow(); dr["picsrc"] = pic; dt.Rows.Add(dr); } this.rptAlbumList.DataSource = dt; this.rptAlbumList.DataBind(); } } }
////////////////////////////////////////////////////////////////////////////////////////////////// /// /// /// Updates the Prestashop ID when change the selected product in the comboBox /// /// /// ////////////////////////////////////////////////////////////////////////////////////////////////// protected void productsBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (productsBox.SelectedItem.ToString() == "-- Selecione un producto para editarlo --") { return; } string id = ""; shortDesc.Document.Blocks.Clear(); largeDesc.Document.Blocks.Clear(); ProductFactory pf = new ProductFactory(ConfigurationManager.AppSettings["baseUrl"].ToString(), ConfigurationManager.AppSettings["accProduct"].ToString(), ""); using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlDB"].ConnectionString.ToString())) { MySqlCommand cmd = new MySqlCommand($"SELECT id_product FROM ps_product_lang WHERE name = '{productsBox.SelectedItem.ToString()}'", conn); conn.Open(); using (MySqlDataReader rdr = cmd.ExecuteReader()) { rdr.Read(); id = rdr[0].ToString(); } } product prod = pf.Get(Int64.Parse(id)); name.Text = prod.name[0].Value; if (prod.active == 1) { yes.IsChecked = true; } else { no.IsChecked = true; } shortDesc.AppendText(prod.description_short[0].Value); largeDesc.AppendText(prod.description[0].Value); price.Text = $"{Decimal.Round(prod.price * (Decimal)1.21, 6)}"; textNoStock.Text = prod.available_later[0].Value; textStock.Text = prod.available_now[0].Value; string idCat = prod.associations.categories[0].id.ToString(); string idMan = prod.id_manufacturer.ToString(); using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlDB"].ConnectionString.ToString())) { MySqlCommand cmd = new MySqlCommand($"SELECT name FROM ps_category_lang WHERE id_category = '{idCat}'", conn); conn.Open(); using (MySqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { rdr.Read(); categoryBox.SelectedItem = rdr[0].ToString(); } } MySqlCommand cmd2 = new MySqlCommand($"SELECT name FROM ps_manufacturer WHERE id_manufacturer = '{idMan}'", conn); using (MySqlDataReader rdr = cmd2.ExecuteReader()) { if (rdr.HasRows) { rdr.Read(); manufacturerBox.SelectedItem = rdr[0].ToString(); } } } }
protected void btnSave_Click(object sender, EventArgs e) { if (this.Action == "add") { ProductModel info = new ProductModel(); info.salecount = Int32.Parse(this.txtsalecount.Text.Trim()); info.productcount = Int32.Parse(this.txtproductcount.Text.Trim()); info.productname = this.txtproductname.Text; info.price = Decimal.Parse(this.txtprice.Text.Trim()); info.itemprice = this.txtitemprice.Text; info.includepicpath = this.txtincludepicpath.Text.Trim(); info.createtime = DateTime.Now; info.categoryid = Int32.Parse(this.ddlProductCategory.SelectedItem.Value); info.iscommend = this.chkiscommend.Checked ? 1 : 0; info.productcode = Int32.Parse(this.rblproductcode.SelectedValue); info.specification = this.editorcontent.Value; //产品相册 string[] albumArr = Request.Form.GetValues("hid_photo_name"); if (albumArr.Length > 0) { string pics = string.Empty; string dotstr = ""; foreach (string sp in albumArr) { pics += dotstr + sp; dotstr = "|"; } info.productpics = pics; } ProductFactory.Add(info); } else if (this.Action == "edit") { int productid = HYRequest.GetQueryInt("productid", 0); ProductModel info = ProductFactory.Get(productid); info.salecount = Int32.Parse(this.txtsalecount.Text.Trim()); info.productcount = Int32.Parse(this.txtproductcount.Text.Trim()); info.productname = this.txtproductname.Text; info.price = Decimal.Parse(this.txtprice.Text.Trim()); info.itemprice = this.txtitemprice.Text; info.includepicpath = this.txtincludepicpath.Text.Trim(); info.createtime = DateTime.Now; info.categoryid = Int32.Parse(this.ddlProductCategory.SelectedItem.Value); info.iscommend = this.chkiscommend.Checked ? 1 : 0; info.productcode = Int32.Parse(this.rblproductcode.SelectedValue); info.specification = this.editorcontent.Value; //产品相册 string[] albumArr = Request.Form.GetValues("hid_photo_name"); if (albumArr.Length > 0) { string pics = string.Empty; string dotstr = ""; foreach (string sp in albumArr) { pics += dotstr + sp; dotstr = "|"; } info.productpics = pics; } ProductFactory.Update(info); } ClientScript.RegisterStartupScript(this.GetType(), "AddEditTips", "<script language=\"javascript\">window.location='productlist.aspx';</script>"); }
public IActionResult Product(int id) { return(Ok(productFactory.Get(id))); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { UserModel userInfo = this.LoginUser; OrderModel myorder = OrderFactory.GetCartOrder(userInfo.uid); int pid = HYRequest.GetQueryInt("pid", 0); int itemflag = HYRequest.GetQueryInt("itemflag", 0); string action = HYRequest.GetQueryString("action"); if (action == "add") //添加商品 { OrderModel myof = myorder; if (myof == null) { myof = new OrderModel(); myof.orderno = Utils.GenerateOutTradeNo(userInfo.uid); //Utils.GetRandomOrderNo(); myof.uid = userInfo.uid; myof.customername = userInfo.fullname; myof.tel = userInfo.tel; myof.address = userInfo.address; } ProductModel p = ProductFactory.Get(pid); OrderProduct op = new OrderProduct(); op.count = 1; op.productinfo = p; op.price = p.price; //判断是否有属性 if (itemflag > 0) { int tmpflag = 1; foreach (KeyValuePair <string, decimal> kvp in p.itempricelist) { if (itemflag == tmpflag) { op.item = kvp.Key; op.price = kvp.Value; break; } tmpflag++; } } CheckIsAdd(myof.productlist, op); if (myorder == null) { OrderFactory.Add(myof); } else { OrderFactory.Update(myof); } Response.Redirect("cart.aspx"); } else if (action == "del") { OrderModel myof = myorder; ProductModel p = ProductFactory.Get(pid); OrderProduct op = new OrderProduct(); op.productinfo = p; op.item = HYRequest.GetQueryString("item"); CheckIsDel(myof.productlist, op); OrderFactory.Update(myof); Response.Redirect("cart.aspx"); } else if (action == "ajaxupdate") //更新数量 { int goods_selected = HYRequest.GetInt("goods_selected", 1); int goods_number = HYRequest.GetInt("goods_number", 1); int rec_id = HYRequest.GetInt("rec_id", 0); string item = HYRequest.GetString("item"); OrderModel myof = myorder; ProductModel p = ProductFactory.Get(rec_id); OrderProduct op = new OrderProduct(); op.isselected = (goods_selected == 1) ? true : false; op.count = goods_number; op.item = item; op.productinfo = p; CheckIsUpdate(myof.productlist, op); OrderFactory.Update(myof); string json = "{\"rec_id\":" + rec_id + ",\"goods_number\":" + goods_number + ",\"total_number\":" + myof.productcount + ",\"total_desc\":" + myof.productprice.ToString() + ",\"postage\":" + myof.postage.ToString() + ",\"error\":0}"; Response.Write(json); Response.Flush(); Response.End(); return; } else if (action == "ajaxupdateall") //全选状态处理 { int goods_selected = HYRequest.GetInt("goods_selected", 1); int rec_id = HYRequest.GetInt("rec_id", 0); OrderModel myof = myorder; foreach (OrderProduct o in myof.productlist) { o.isselected = (goods_selected == 1) ? true : false; } OrderFactory.Update(myof); string json = "{\"rec_id\":" + rec_id + ",\"total_number\":" + myof.productcount + ",\"total_desc\":" + myof.productprice.ToString() + ",\"postage\":" + myof.postage.ToString() + ",\"error\":0}"; Response.Write(json); Response.Flush(); Response.End(); return; } if (myorder != null && myorder.productcount > 0) { this.phNoProduct.Visible = false; CartOrder = myorder; } else { this.phNoProduct.Visible = true; } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { string action = HYRequest.GetQueryString("action"); UserModel userInfo = this.LoginUser; OrderModel myorder = OrderFactory.GetCartOrder(userInfo.uid); if (action == "addtocart") //添加到购物车 { #region ==addtocart== int pid = HYRequest.GetFormInt("pid", 0); int buycount = HYRequest.GetFormInt("buycount", 0); int itemflag = HYRequest.GetFormInt("itemflag", 0); OrderModel myof = myorder; if (myof == null) { myof = new OrderModel(); myof.orderno = Utils.GenerateOutTradeNo(this.LoginUser.uid); myof.uid = userInfo.uid; myof.customername = userInfo.fullname; myof.tel = userInfo.tel; myof.address = userInfo.address; } ProductModel p = ProductFactory.Get(pid); OrderProduct op = new OrderProduct(); op.count = buycount; op.productinfo = p; op.price = p.price; //判断是否有属性 if (itemflag > 0) { int tmpflag = 1; foreach (KeyValuePair <string, decimal> kvp in p.itempricelist) { if (itemflag == tmpflag) { op.item = kvp.Key; op.price = kvp.Value; break; } tmpflag++; } } CheckIsAdd(myof.productlist, op); if (myorder == null) { OrderFactory.Add(myof); } else { OrderFactory.Update(myof); } string json = "{\"shopcount\":" + myof.productlist.Count + ",\"error\":0}"; Response.Write(json); Response.Flush(); Response.End(); return; #endregion } else if (action == "addtofav") //添加到收藏夹 { #region ==addtofav== int pid = HYRequest.GetFormInt("pid", 0); bool isfav = FavoriteFactory.IsFavorite(this.LoginUser.uid, pid); if (!isfav) { FavoriteModel fm = new FavoriteModel(); fm.product = ProductFactory.Get(pid); fm.uid = this.LoginUser.uid; fm.productid = pid; FavoriteFactory.Add(fm); } string json = "{\"favtip\":\"已收藏\",\"error\":0}"; Response.Write(json); Response.Flush(); Response.End(); return; #endregion } else if (action == "delfav") //删除收藏夹 { int fid = HYRequest.GetFormInt("fid", 0); FavoriteFactory.Delete(fid); } } }