public async Task <List <NewsDto> > GetAllNews() { using (IDAL.INewsService Svc = new DAL.NewsService()) { return(await Svc.GetAllAsync().Select(m => new Dto.NewsDto() { CategoryId = m.CategoryId, Title = m.Title, Content = m.Content, CategoryName = m.NewsCategory.CategoryName }).ToListAsync()); } }
public async Task AddNews(string title, string content, string categoryId) { using (IDAL.INewsService Svc = new DAL.NewsService()) { await Svc.CreateAsync(new News() { ModifyTime = DateTime.Now, Title = title, Content = content, CategoryId = categoryId }); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string newsId = Request.Params["NewsId"]; if (newsId != null && newsId != string.Empty) { News objNews = new DAL.NewsService().GetNewsById(newsId); if (objNews == null) { Response.Redirect("~/Default.aspx"); } else { this.newsContents.InnerHtml = objNews.NewsContents; this.newsTitle.InnerText = objNews.NewsTitle; this.publishTime.InnerText = "发布时间:" + objNews.PublishTime.ToShortDateString(); } } } }