public ActionResult AddGameProduct(LastProductedModel model) { var newlastprod = new LastProductedModel(); //存储上传图片文件 var file = Request.Files["pic"]; if(file!=null) { var filepath = Path.Combine(HttpContext.Server.MapPath("~/assets/images/Product"), Path.GetFileName(file.FileName)); newlastprod.ProductImgSrc = "assets/images/Product/" + Path.GetFileName(file.FileName); file.SaveAs(filepath); } newlastprod.ProductName = model.ProductName; newlastprod.ProductDescribe = model.ProductDescribe; newlastprod.ProductPublishTime = DateTime.Now; _db.LastProductedModule.Add(newlastprod); _db.SaveChanges(); return View("BackGround_GameProject"); }
public ActionResult EditGameProject(LastProductedModel model) { if (!ModelState.IsValid) return View("BackGround_GameProject"); var nowEditModel = _db.LastProductedModule.FirstOrDefault(it => it.id == model.id); if (nowEditModel != null) { nowEditModel.ProductName = model.ProductName; nowEditModel.ProductPublishTime = DateTime.Now; nowEditModel.ProductDescribe = model.ProductDescribe; nowEditModel.ProductImgSrc = model.ProductImgSrc; } _db.SaveChanges(); return View("BackGround_GameProject"); }