public ActionResult AddNewAnnounce(AnnounceModel announceModel) { if (!ModelState.IsValid) { return View(announceModel); } try { string updateBy = AccountInfo.GetUserName(Request); AnnouncementTableAdapter announceTableAdapter = new AnnouncementTableAdapter(); string title = announceModel.title; string subject = announceModel.subject; Boolean isAuto = false; DateTime date = DateTime.Now; announceTableAdapter.InsertNewAnnounce(title, subject, isAuto, date, updateBy, date); Session["addAnnounce"] = "Đăng tin thành công!"; } catch (Exception ex) { Log.ErrorLog(ex.Message); Session["addAnnounce"] = "Đăng tin thất bại!"; } return RedirectToAction("AddNewAnnounce", "Announce"); }
public ActionResult EditAnnounce(string announceID) { AnnounceModel announcement = new AnnounceModel(); AnnouncementTableAdapter announcementAdapter = new AnnouncementTableAdapter(); try { int announceId = Convert.ToInt32(announceID); DataTable announcementTable = announcementAdapter.GetDataByAnnounceID(announceId); announcement.annoucemenID = Convert.ToInt32(announcementTable.Rows[0]["AnnouncementID"]); announcement.title = Convert.ToString(announcementTable.Rows[0]["Title"]); announcement.isAuto = Convert.ToBoolean(announcementTable.Rows[0]["IsAuto"]); announcement.subject = Convert.ToString(announcementTable.Rows[0]["Subject"]); } catch (Exception ex) { Log.ErrorLog(ex.Message); return RedirectToAction("Error", "ErrorController"); } return View(announcement); }
public ActionResult EditAnnounce(AnnounceModel announceModel, string announceID) { AnnouncementTableAdapter announceTableAdapter = new AnnouncementTableAdapter(); try { int announceId = Convert.ToInt32(announceID); string updateBy = AccountInfo.GetUserName(Request); string title = announceModel.title; string subject = announceModel.subject; Boolean isAuto = false; DateTime date = DateTime.Now; announceTableAdapter.UpdateAnnounce(title, subject, isAuto, updateBy, date, announceId); Session["editAnnounce"] = "Cập nhật thành công!"; } catch (Exception ex) { Log.ErrorLog(ex.Message); Session["editAnnounce"] = "Cập nhật thất bại!"; } return RedirectToAction("EditAnnounce", "Announce", new { @announceID = announceID }); }