public ActionResult Create(Model.EntityFramework.Content model) { if (ModelState.IsValid) { var dao = new ContentDAO(); int result = dao.Create(model); if (result > 0) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Có lỗi xảy ra thử lại sau."); } } SetViewBag((int)model.CategoryID); return(View()); }
public ActionResult Create(Content entities) { if (ModelState.IsValid) { var db = new ContentDAO(); var dao = db.Create(entities, Session["username"].ToString()); if (dao > 0) { TempData["Success"] = "Thêm thành công"; setViewBag(); return(RedirectToAction("Index", "Content")); } else { ModelState.AddModelError("", "Thêm thất bại "); } } TempData["Error"] = "Thêm thất bại"; setViewBag(); return(View()); }
public ActionResult Create(Content content) { if (ModelState.IsValid) { try { if (dao.Create(content)) { return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Create failure"); return(View()); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View()); } } return(View()); }