//把news插入到数据库 protected void ButtonPuslish_Click(object sender, EventArgs e) { Guid id = Guid.NewGuid(); DateTime publishTime = new DateTime(); publishTime = DateTime.Now; //实例化一个news News news = new News(id, TextBoxTitle.Text, TextBoxContent.Text, publishTime, DropDownListDish.SelectedItem.Text); manager.PublishNews(news); Response.Write("<Script>alert('news is published successfully')</Script>"); // }
//Function: insert a news in db public void PublishNews(News pNews) { DataContextDataContext dc = new DataContextDataContext(); dc.insert_news(pNews.id, pNews.title, pNews.content, (DateTime?)pNews.publishTime, pNews.aboutDish); }
public static List<News> GetNews() { List<News> newsList = new List<News>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_newsResult> rs = dc.select_all_news(); foreach (select_all_newsResult r in rs) { News news = new News((Guid)r.id, r.title, r.content, (DateTime)r.publish_time, r.about_dish); newsList.Add(news); } return newsList; }