public ActionResult Create(bai_viet bai_viet) { if (ModelState.IsValid) { bai_viet.nguoi_dang = Convert.ToInt16(Session["USER_ID"]); bai_viet.ngay_dang = bai_viet.ngay_sua = DateTime.Now; bai_viet.so_binh_luan = 0; bai_viet.so_luot_xem = 0; db.bai_viet.Add(bai_viet); try { db.SaveChanges(); return RedirectToAction("Index"); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } } ViewBag.ma_the_loai = new SelectList(db.the_loai_bai_viet, "id", "mo_ta", bai_viet.ma_the_loai); return View(bai_viet); }
public ActionResult Edit(bai_viet bai_viet) { bai_viet.so_binh_luan = bai_viet.so_binh_luan; bai_viet.so_luot_xem = bai_viet.so_luot_xem; bai_viet.nguoi_dang = Convert.ToInt16(Session["USER_ID"]); bai_viet.ngay_sua = DateTime.Now; if (ModelState.IsValid) { db.Entry(bai_viet).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.ma_the_loai = new SelectList(db.the_loai_bai_viet, "id", "mo_ta", bai_viet.ma_the_loai); return View(bai_viet); }