public ActionResult AnnouncementFormView(int?id) { if (id == null) { return(View()); } else { Models.AnnouncementModel model = null; using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[Announcement_Table] WHERE Id = " + Convert.ToString(id), cn); cn.Open(); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { model = new Models.AnnouncementModel(); model.Id = Int32.Parse(Convert.ToString(rd.GetSqlValue(0))); model.Content = Convert.ToString(rd.GetSqlValue(1)); model.Datetime = Convert.ToDateTime(Convert.ToString(rd.GetSqlValue(2))); model.AuthorName = Convert.ToString(rd.GetSqlValue(3)); model.Category = Convert.ToString(rd.GetSqlValue(4)); model.Title = Convert.ToString(rd.GetSqlValue(5)); } } return(View(model)); } }
public bool SaveAnnouncement(Models.AnnouncementModel model) { String _sql = ""; using (SqlConnection cn = new SqlConnection(connectionString)) { model.AuthorName = ViewBag.Username; model.Datetime = DateTime.Now; int?id = model.Id; if (id == 0) { _sql = "INSERT INTO [dbo].[Announcement_Table] VALUES ('" + model.Content + "', '" + model.Datetime + "', '" + model.AuthorName + "', '" + model.Category + "', '" + model.Title + "')"; } else { _sql = "UPDATE [dbo].[Announcement_Table] " + "SET Contents = '" + model.Content + "', Title = '" + model.Title + "', Category ='" + model.Category + "' WHERE Id = " + Convert.ToString(model.Id); } SqlCommand cmd = new SqlCommand(_sql, cn); cn.Open(); cmd.ExecuteNonQuery(); } return(true); }
public List <Models.AnnouncementModel> getAnnouncement() { Models.AnnouncementModel model = null; List <Models.AnnouncementModel> announcements = new List <Models.AnnouncementModel>(); using (SqlConnection cn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[Announcement_Table] ORDER BY Datetime DESC", cn); cn.Open(); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { model = new Models.AnnouncementModel(); model.Id = Int32.Parse(Convert.ToString(rd.GetSqlValue(0))); model.Content = Convert.ToString(rd.GetSqlValue(1)); model.Datetime = Convert.ToDateTime(Convert.ToString(rd.GetSqlValue(2))); model.AuthorName = Convert.ToString(rd.GetSqlValue(3)); model.Category = Convert.ToString(rd.GetSqlValue(4)); model.Title = Convert.ToString(rd.GetSqlValue(5)); announcements.Add(model); } } return(announcements); }
public ActionResult Create(FormCollection collection) { try { Models.AnnouncementModel announcementModel = new Models.AnnouncementModel(); UpdateModel(announcementModel); if (User.Identity.IsAuthenticated) { announcementModel.Title = User.Identity.Name + " : " + announcementModel.Title; announcementModel.Tags = announcementModel.Tags + " , " + User.Identity.Name; } announcementRepository.InsertAnnouncement(announcementModel); // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View("CreateAnnouncement")); } }
// GET: Announcement/Details/5 public ActionResult Details(Guid id) { Models.AnnouncementModel announcementModel = announcementRepository.GetAnnouncementByID(id); return(View("AnnouncementDetails", announcementModel)); }
public ActionResult AnnouncementFormView(Models.AnnouncementModel model) { if (SaveAnnouncement(model)) { return(RedirectToAction("AnnouncementView")); } return(View(model)); }
public ActionResult Edit(Guid id, FormCollection collection) { try { Models.AnnouncementModel announcementModel = new Models.AnnouncementModel(); UpdateModel(announcementModel); announcementRepository.UpdateAnnouncement(announcementModel); // TODO: Add update logic here return(RedirectToAction("Index")); } catch { return(View("EditAnnouncement")); } }
public bool SaveAnnouncement(Models.AnnouncementModel model) { String _sql = ""; using (SqlConnection cn = new SqlConnection(connectionString)) { model.AuthorName = ViewBag.Username; model.Datetime = DateTime.Now; model.Content = model.Content.Replace("\r\n", "<br />"); int?id = model.Id; if (id == 0) { _sql = @"INSERT INTO [dbo].[Announcement_Table] VALUES ('" + model.Content + "', '" + Convert.ToString(model.Datetime) + "', '" + model.AuthorName + "', '" + model.Category + "', '" + model.Title + "')"; } else { _sql = @"UPDATE [dbo].[Announcement_Table] " + "SET Contents = '" + model.Content + "', Title = '" + model.Title + "', Category ='" + model.Category + "' WHERE Id = " + Convert.ToString(model.Id); } SqlCommand cmd = new SqlCommand(_sql, cn); cn.Open(); try { } catch (Exception) { return(false); } return(true); } }
// GET: Announcement/Edit/5 public ActionResult Edit(Guid id) { Models.AnnouncementModel announcementModel = announcementRepository.GetAnnouncementByID(id); return(View("EditAnnouncement", announcementModel)); }