public ActionResult Edit(adv_machine_product_list adv_machine_product_list) { if (ModelState.IsValid) { db.adv_machine_product_list.Attach(adv_machine_product_list); db.ObjectStateManager.ChangeObjectState(adv_machine_product_list, EntityState.Modified); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(adv_machine_product_list)); }
public static bool DeleteProduct(string productname) { try { using (productEntities db = new productEntities()) { ProductsTable Product = db.ProductsTables.FirstOrDefault(a => a.ProductName == productname); if (Product == null) { return(false); } db.ProductsTables.Remove(Product); db.SaveChanges(); return(true); } } catch { return(false); } }
public ActionResult Create(tbl_product tbl_product) { if (ModelState.IsValid) { tbl_product.product_status = true; tbl_product.create_time = DateTime.Now; //处理长链接为短连接 获取二维码 并存储 string webUrl = ""; webUrl = Config.ConfigManager.getConfig("get-ticket-url"); webUrl = webUrl.Replace("EVENT_ID", "" + tbl_product.product_id); WebRequest webRequest = WebRequest.Create(webUrl); HttpWebRequest request = webRequest as HttpWebRequest; request.Method = "GET"; WebResponse response = request.GetResponse(); String ticketUrl = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd(); tbl_product.ticket_url = ticketUrl; webUrl = Config.ConfigManager.getConfig("get-short-url"); byte[] dataArray = Encoding.UTF8.GetBytes(tbl_product.content_url); webRequest = WebRequest.Create(webUrl); request = webRequest as HttpWebRequest; request.Method = "POST"; request.ContentLength = dataArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(dataArray, 0, dataArray.Length); dataStream.Close(); response = request.GetResponse(); String shortUrl = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd(); tbl_product.short_url = shortUrl; db.tbl_product.AddObject(tbl_product); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tbl_product)); }