日期:2014-05-18 浏览次数:20401 次
public class EFProductRepository : IProductRepository { private EFDbContext context = new EFDbContext(); public IQueryable<Product> Products { get { return context.Products; } } public void SaveProduct(Product product) { if (product.ProductID == 0) { context.Products.Add(product); } context.SaveChanges(); } } [HttpPost] public ActionResult Edit(Product product) { if (ModelState.IsValid) { repository.SaveProduct(product); TempData["Message"] = string.Format("{0} have been saving.", product.Name); return RedirectToAction("Index"); } else { return View(product); } }