public ActionResult ThemMoiBaiViet(BaiVietVeDiaDiem objBaiViet, HttpPostedFileBase fUpload, int?idDiaDiem = null, int?idChuDe = null) { try { HienThiDanhSachDiaDiem(); HienThiDanhSachChuDe(); if (ModelState.IsValid) { objBaiViet.DataCreated = DateTime.Now; //Xử lý upload file if (fUpload != null && fUpload.ContentLength > 0) { //Upload fUpload.SaveAs(Server.MapPath("~/Content/Image/BaiViet/" + fUpload.FileName)); //Lưu vào db objBaiViet.PictureId = fUpload.FileName; } //thêm vào database DataProvider.Entities.BaiVietVeDiaDiems.Add(objBaiViet); //Lưu thay đổi DataProvider.Entities.SaveChanges(); logger.Info("Add a Blog " + objBaiViet.TenBaiViet); } return(RedirectToAction("DanhSachBaiViet")); } catch (Exception ex) { logger.Error(ex.ToString()); return(Redirect("~/ErrorPage/Return")); } }
public ActionResult CapNhatBaiViet(int Id) { try { HienThiDanhSachDiaDiem(); HienThiDanhSachChuDe(); BaiVietVeDiaDiem objBaiViet = DataProvider.Entities.BaiVietVeDiaDiems.Where(c => c.Id == Id).Single(); return(View(objBaiViet)); } catch (Exception ex) { logger.Error(ex.ToString()); return(Redirect("~/ErrorPage/Return")); } }
public ActionResult BlogDetail(int?Id) { try { BaiVietVeDiaDiem ObjbaiVietVeDiaDiem = DataProvider.Entities.BaiVietVeDiaDiems.Where(b => b.Id == Id).First(); if (ObjbaiVietVeDiaDiem == null) { return(RedirectToAction("Return", "ErrorPage")); } return(View(ObjbaiVietVeDiaDiem)); } catch (Exception ex) { logger.Error(ex.ToString()); return(RedirectToAction("Return", "ErrorPage")); } }
public ActionResult XoaBaiViet(int Id) { try { BaiVietVeDiaDiem objBaiViet = DataProvider.Entities.BaiVietVeDiaDiems.Find(Id); if (objBaiViet != null) { //Xóa DataProvider.Entities.BaiVietVeDiaDiems.Remove(objBaiViet); //Lưu thay đổi DataProvider.Entities.SaveChanges(); logger.Info("Delete a Blog " + objBaiViet.TenBaiViet); } return(RedirectToAction("DanhSachBaiViet")); } catch (Exception ex) { logger.Error(ex.ToString()); return(Redirect("~/ErrorPage/Return")); } //Lấy đối tượng }
public ActionResult CapNhatBaiViet(int Id, BaiVietVeDiaDiem objBaiViet, HttpPostedFileBase fUpload) { try { var objOld_BaiViet = DataProvider.Entities.BaiVietVeDiaDiems.Find(Id); string img_Name = ""; //Xử lý upload file if (fUpload != null && fUpload.ContentLength > 0) { //Upload fUpload.SaveAs(Server.MapPath("~/Content/Image/BaiViet/" + fUpload.FileName)); //Lưu vào db objBaiViet.PictureId = fUpload.FileName; img_Name = fUpload.FileName; } if (objOld_BaiViet != null) { if (string.IsNullOrEmpty(img_Name)) { objBaiViet.DataCreated = objOld_BaiViet.DataCreated; objBaiViet.PictureId = objOld_BaiViet.PictureId; } DataProvider.Entities.Entry(objOld_BaiViet).CurrentValues.SetValues(objBaiViet); //Lưu thay đổi DataProvider.Entities.SaveChanges(); } logger.Info("Update a Blog " + objBaiViet.TenBaiViet); return(RedirectToAction("DanhSachBaiViet")); } catch (Exception ex) { logger.Error(ex.ToString()); return(Redirect("~/ErrorPage/Return")); } }