public ActionResult Create([Bind(Include = "HinhAnh,NoiBo")] tb_BaiViet tb_baiviet) { tb_baiviet.LoaiBaiViet = 3; tb_baiviet.NgayViet = DateTime.Now; tb_baiviet.NguoiViet = HttpContext.Session["username"] as string ?? ""; if (ModelState.IsValid) { db.tb_BaiViet.Add(tb_baiviet); db.SaveChanges(); } tb_BaiVietTrans tb_bvVn = new tb_BaiVietTrans(); tb_bvVn.MaBV = tb_baiviet.MaBV; tb_bvVn.NgonNgu = "vi"; tb_bvVn.TieuDeTrans = Request.Form["TieuDeVn"]; tb_bvVn.TomTatTrans = Request.Form["TomTatVn"]; tb_bvVn.NoiDungTrans = Request.Form["NoiDungVn"]; db.tb_BaiVietTrans.Add(tb_bvVn); tb_BaiVietTrans tb_bvEn = new tb_BaiVietTrans(); tb_bvEn.MaBV = tb_baiviet.MaBV; tb_bvEn.NgonNgu = "en"; tb_bvEn.TieuDeTrans = Request.Form["TieuDeEn"]; tb_bvEn.TomTatTrans = Request.Form["TomTatEn"]; tb_bvEn.NoiDungTrans = Request.Form["NoiDungEn"]; db.tb_BaiVietTrans.Add(tb_bvEn); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "MaBV,HinhAnh,NoiBo")] tb_BaiViet tb_baiviet) { tb_baiviet.NguoiViet = HttpContext.Session["username"] as string ?? ""; tb_baiviet.LoaiBaiViet = 3; tb_baiviet.NgayViet = DateTime.Now; if (ModelState.IsValid) { db.Entry(tb_baiviet).State = EntityState.Modified; db.SaveChanges(); } tb_BaiVietTrans tb_bvVn = db.tb_BaiVietTrans.Where(t => t.NgonNgu == "vi" && t.MaBV == tb_baiviet.MaBV).FirstOrDefault(); tb_bvVn.TieuDeTrans = Request.Form["TieuDeVn"]; tb_bvVn.TomTatTrans = Request.Form["TomTatVn"]; tb_bvVn.NoiDungTrans = Request.Form["NoiDungVn"]; db.Entry(tb_bvVn).State = EntityState.Modified; tb_BaiVietTrans tb_bvEn = db.tb_BaiVietTrans.Where(t => t.NgonNgu == "en" && t.MaBV == tb_baiviet.MaBV).FirstOrDefault(); tb_bvEn.TieuDeTrans = Request.Form["TieuDeEn"]; tb_bvEn.TomTatTrans = Request.Form["TomTatEn"]; tb_bvEn.NoiDungTrans = Request.Form["NoiDungEn"]; db.Entry(tb_bvEn).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: /Admin/ThongBao/Edit/5 public ActionResult Edit(int?id) { tb_BaiViet tb_baiviet = db.tb_BaiViet.Include(t => t.tb_BaiVietTrans).Where(t => t.MaBV == id).FirstOrDefault(); if (tb_baiviet == null) { return(HttpNotFound()); } return(View(tb_baiviet)); }
// GET: /Admin/ThongBao/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tb_BaiViet tb_baiviet = db.tb_BaiViet.Include(t => t.tb_BaiVietTrans).Where(t => t.MaBV == id).FirstOrDefault(); if (tb_baiviet == null) { return(HttpNotFound()); } return(View(tb_baiviet)); }
public ActionResult DeleteConfirmed(int id) { tb_BaiViet tb_baiviet = db.tb_BaiViet.Find(id); List <tb_BaiVietTrans> dsTrans = tb_baiviet.tb_BaiVietTrans.ToList(); for (int i = 0; i < dsTrans.Count; i++) { db.tb_BaiVietTrans.Remove(dsTrans[i]); } db.SaveChanges(); db.tb_BaiViet.Remove(tb_baiviet); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: /Admin/ThongBao/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tb_BaiViet tb_baiviet = db.tb_BaiViet.Find(id); if (tb_baiviet == null) { return(HttpNotFound()); } return(View(tb_baiviet)); }