Beispiel #1
0
        public ActionResult AddProduct(Product product,HttpPostedFileBase pdf)
        {
            try
            {
                if (!Directory.Exists(Server.MapPath("/pdf/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("/pdf/"));
                }
                //图片保存的地址和名称
                Random random = new Random(DateTime.Now.Millisecond);
                string filename = DateTime.Now.ToString("yyyyMMddhhmmss.") + pdf.FileName.Substring(pdf.FileName.LastIndexOf('.') + 1);
                string filePath = Path.Combine(HttpContext.Server.MapPath("../pdf/"), filename);
                if (pdf.ContentLength > 0)
                {
                    pdf.SaveAs(filePath);
                    product.pdfpath= filename;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            if (product.id <= 0)
                product.createtime = DateTime.Now;
            ProductService.GetInstance().Save(product);
            return RedirectToAction("products");
        }
 partial void DeleteProduct(Product instance);
 partial void InsertProduct(Product instance);
 partial void UpdateProduct(Product instance);
Beispiel #5
0
 public void Save(Product product)
 {
     if (product.id > 0)
         _productDao.Update(product);else
     _productDao.Insert(product);
 }