protected void btnSubmit_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"]); try { if (Label2.Text.Trim() == "") { Response.Write("<script>alert('照片不能为空!')</script>"); } else { Newsinfo news = new Newsinfo(); news.Cull_ID = id; news.News_Title = txtTitle.Text.Trim(); news.News_Content = CKEditorControl1.Text.Trim(); news.News_Img = Label2.Text; news.News_Time = DateTime.Now; int result = NewsService.Insert(news); if (result >= 1) { Response.Write("<script>alert('发布成功!')</script>"); } } } catch (Exception ex) { Response.Write("<script>alert('上传失败');</script> 原因是:" + ex); } }
public async Task <IActionResult> PutNewsinfo([FromRoute] int id, [FromBody] Newsinfo newsinfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != newsinfo.Newsserial) { return(BadRequest()); } _context.Entry(newsinfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsinfoExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <List <Newsinfo> > GetNewsAsync(SiteInfo siteInfo) { List <Newsinfo> newsInfoDb = new List <Newsinfo> (); var config = Configuration.Default.WithDefaultLoader(); var context = BrowsingContext.New(config); var document = await context.OpenAsync(siteInfo.Url); var newsContent = document.QuerySelectorAll(siteInfo.NewsSectionClass); foreach (var item in newsContent) { var eachNews = new Newsinfo() { Title = item.QuerySelector(siteInfo.TitleClass).TextContent.ToUpper(), Summary = item.QuerySelector(siteInfo.SummaryClass).TextContent, Link = item.QuerySelector(siteInfo.LinkClass).GetAttribute("href"), Date = item.QuerySelector(siteInfo.DateClass).TextContent }; newsInfoDb.Add(eachNews); } return(newsInfoDb); }
public async Task <IActionResult> Edit(int id, [Bind("Newsserial,Title,Category,Description,Author,Datetime,Keyword,CaptionPicture,Editor,FeatureNews")] Newsinfo newsinfo) { if (id != newsinfo.Newsserial) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(newsinfo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewsinfoExists(newsinfo.Newsserial)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(newsinfo)); }
public ActionResult CaptionImage(IFormFile file, int id) { try { if (file == null || file.Length == 0) { return(Content("File not selceted")); } if (file.Length > 0) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "featuresNews/" + file.FileName); using (var stream = new FileStream(path, FileMode.Create)) { file.CopyTo(stream); } Newsinfo st = (from s in _context.Newsinfo where s.Newsserial == id select s).First(); st.CaptionPicture = file.FileName; _context.SaveChanges(); } ViewBag.Message = "File Uploaded Successfully!" + ":" + id; return(RedirectToAction("Index")); } catch (Exception) { ViewBag.Message = "File upload failes!"; return(View()); } }
public ActionResult Delete(int id = 0) { Newsinfo newsinfo = newsinfoService.GetEntities(u => (u.Delflag == (int)DelflagEnum.Normal && u.ID == id)).First(); if (newsinfoService.Delete(newsinfo)) { return(Json("ok")); } return(HttpNotFound()); }
public ActionResult Details(int id = 0) { Newsinfo newsinfo = newsinfoService.GetEntities(u => (u.Delflag == (int)DelflagEnum.Normal && u.ID == id)).First(); if (newsinfo == null) { return(HttpNotFound()); } return(View(newsinfo)); }
public async Task <IActionResult> Create([Bind("Newsserial,Title,Category,Description,Author,Datetime,Keyword,CaptionPicture,Editor,FeatureNews")] Newsinfo newsinfo) { if (ModelState.IsValid) { _context.Add(newsinfo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(newsinfo)); }
public async Task <IActionResult> PostNewsinfo(Newsinfo newsinfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Newsinfo.Add(newsinfo); await _context.SaveChangesAsync(); return(CreatedAtAction("GetNewsinfo", new { id = newsinfo.Newsserial }, newsinfo)); }
//后台新闻增加 public int Insert(Newsinfo news) { string sql = "insert into News(News_Title,News_Img,News_Content,Cull_ID,News_Time) values(@News_Title,@News_Img,@News_Content,@Cull_ID,@News_Time)"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@News_Title", news.News_Title), new SqlParameter("@News_Img", news.News_Img), new SqlParameter("@News_Content", news.News_Content), new SqlParameter("@Cull_ID", news.Cull_ID), new SqlParameter("@News_Time", news.News_Time) }; return(DBHelper.GetExcuteNonQuery(sql, sp)); }
public List <Newsinfo> CategorywiseNews() { List <Newsinfo> a1 = new List <Newsinfo>(); Newsinfo b = new Newsinfo(); var Sports = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "Sports" select a).LastOrDefault(); b.Newsserial = Sports.Newsserial; b.Title = Sports.Title; b.CaptionPicture = Sports.CaptionPicture; b.Datetime = Sports.Datetime; b.Category = Sports.Category; a1.Add(b); Newsinfo b1 = new Newsinfo(); Sports = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "Entertainment" select a).LastOrDefault(); b1.Newsserial = Sports.Newsserial; b1.Title = Sports.Title; b1.CaptionPicture = Sports.CaptionPicture; b1.Datetime = Sports.Datetime; b1.Category = Sports.Category; a1.Add(b1); b = new Newsinfo(); Sports = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "Politics" select a).LastOrDefault(); b.Newsserial = Sports.Newsserial; b.Title = Sports.Title; b.CaptionPicture = Sports.CaptionPicture; b.Datetime = Sports.Datetime; b.Category = Sports.Category; a1.Add(b); b = new Newsinfo(); Sports = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "National" select a).LastOrDefault(); b.Newsserial = Sports.Newsserial; b.Title = Sports.Title; b.CaptionPicture = Sports.CaptionPicture; b.Datetime = Sports.Datetime; b.Category = Sports.Category; a1.Add(b); //var Entertainment = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "Entertainment" select a).ToList().LastOrDefault(); //var Politics = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "Politics" select a).ToList().LastOrDefault(); //var National = (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "National" select a).ToList().LastOrDefault(); //return (from a in _context.Newsinfo orderby a.Datetime descending where a.Category == "Sports" where a.Category == "Entertainment" where a.Category == "Politics" where a.Category == "National" select a).Distinct().LastOrDefault(); return(a1); }
public ActionResult Index(PagingInfo pi, Newsinfo ni) { pi.PageIndex = pi.PageIndex == 0 ? 1 : pi.PageIndex; pi.PageSize = pi.PageSize == 0 ? 5 : pi.PageSize; //string uname = Request["uname"]; //mr.Userinfo.Uname = String.IsNullOrWhiteSpace(mr.Userinfo.Uname) ? "" : mr.Userinfo.Uname; //ni.Number = String.IsNullOrWhiteSpace(mr.Number) ? "" : mr.Number; //ni.Name = String.IsNullOrWhiteSpace(mr.Name) ? "" : mr.Name; Expression <Func <Newsinfo, bool> > wherelambda = u => (u.Delflag == (int)DelflagEnum.Normal); int count = 0; var newsinfolist = newsinfoService.GetPageEntities <int>(pi.PageSize, pi.PageIndex, out count, wherelambda, u => u.ID, false).ToList(); pi.TotalItems = count; return(Json(Tuple.Create(newsinfolist, pi))); }
public ActionResult Create(Newsinfo ni, FormCollection form) { if (ModelState.IsValid) { //这里注意必须使用 FormCollection form 获得富文本编辑器的内容 //[ValidateInput(false)] 还需要加上这个,因为富文本编辑器传过来的是html代码。不这样会报错 string editorValue = form["editorValue"]; ni.Content = editorValue; ni.Delflag = (int)DelflagEnum.Normal; ni.Inputdate = DateTime.Now; //从缓存里面拿到userLoginId信息 string userLoginId = Request.Cookies["userLoginId"].Value.ToString(); Userinfo userInfo = CacheHelper.GetCache(userLoginId) as Userinfo; ni.UserinfoID = userInfo.ID; newsinfoService.Add(ni); return(Json("ok")); } return(View()); }
public ActionResult Edit(Newsinfo ni, FormCollection form) { if (ModelState.IsValid) { Newsinfo newsinfo = newsinfoService.GetEntities(u => (u.Delflag == (int)DelflagEnum.Normal && u.ID == ni.ID)).First(); //这里注意必须使用 FormCollection form 获得富文本编辑器的内容 //[ValidateInput(false)] 还需要加上这个,因为富文本编辑器传过来的是html代码。不这样会报错 string editorValue = form["editorValue"]; newsinfo.Content = editorValue; newsinfo.Inputdate = DateTime.Now; newsinfo.Showtime = ni.Showtime; newsinfo.Endtime = ni.Endtime; newsinfo.Title = ni.Title; newsinfo.Other = ni.Other; //从缓存里面拿到userLoginId信息 string userLoginId = Request.Cookies["userLoginId"].Value.ToString(); Userinfo userInfo = CacheHelper.GetCache(userLoginId) as Userinfo; newsinfo.UserinfoID = userInfo.ID; newsinfoService.Update(newsinfo); return(Json("ok")); } return(View()); }
//后台增加新闻 public static int Insert(Newsinfo news) { return(inewsinfo.Insert(news)); }