public int AddEditBaiViet(AddBaiViet model) { int kq = 0; bool isAdd = true; BaiViet baiviet = new BaiViet(); baiviet.ID = model.ID.Value; baiviet.IDLoaiBaiViet = model.IDLoaiBaiViet; baiviet.TieuDe = model.TenBaiViet; baiviet.NoiDung = model.NoiDung; baiviet.linkIMG = model.linkIMG; if (model.ID == null) { isAdd = false; baiviet.isCapNhat = true; baiviet.NgayCapNhat = DateTime.Now; } else { baiviet.IDNguoiTao = null;// nua cap nhat sau baiviet.NgayTao = DateTime.Now; } using (var db = new DB_ForumEntities()) { if (isAdd) { db.BaiViets.Add(baiviet); } db.SaveChanges(); } return(kq); }
public ActionResult CreateBaiViet(AddBaiViet model) { if (ModelState.IsValid) { int kq = service.AddEditBaiViet(model); } return(Redirect("Home/Index")); }
// GET: BaiViet public ActionResult CreateBaiViet() { AddBaiViet model = new AddBaiViet(); return(View(model)); }