예제 #1
0
 public ActionResult Show(int id)
 {
     News news = new News();
     news = db.News.Find(id);
     news.Browses = news.Browses + 1;
     db.SaveChanges();
     vNews _news = new vNews(news);
     List<News> lstNews = new List<News>();
     lstNews = db.News.Where(n =>n.NewsTypeID ==news.NewsTypeID && n.ID!=id).OrderByDescending(n=>n.Time).Take(8).ToList();
     ViewBag.News = _news;
     ViewBag.LstNews = lstNews;
     return View();
 }
예제 #2
0
 /// <summary>
 ///  新闻详细信息
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult NewsShow(int id)
 {
     News news = new News();
     news = db.News.Find(id);
     ViewBag.News = news;
     return View();
 }
예제 #3
0
 public ActionResult NewsEdit(News model)
 {
     News news = new News();
     news = db.News.Find(model.ID);
     news.NewsTypeID = model.NewsTypeID;
     news.Title = model.Title;
     news.Content = model.Content;
     db.SaveChanges();
     return RedirectToAction("NewsManager");
 }
예제 #4
0
        public ActionResult NewsEdit(int id)
        {
            News news = new News();
            List<TypeDictionary> newsTypes = new List<TypeDictionary>();
            news = db.News.Find(id);
            newsTypes = db.TypeDictionaries.Where(td => td.FatherID == 0 && td.Belonger == TypeBelonger.新闻).ToList();

            var second = new List<TypeDictionary>();
            second = db.TypeDictionaries.Where(td => td.FatherID == news.TypeDictionary.FatherID).ToList();

            ViewBag.Second = second;
            ViewBag.News = news;
            ViewBag.Types = newsTypes;
            return View();
        }
예제 #5
0
 public ActionResult NewsDelete(int id)
 {
     News news = new News();
     news = db.News.Find(id);
     db.News.Remove(news);
     db.SaveChanges();
     return Content("ok");
 }
예제 #6
0
 public ActionResult AddNews(News model)
 {
     model.UserID = CurrentUser.ID;
     model.Time = DateTime.Now;
     model.Browses = 0;
     db.News.Add(model);
     db.SaveChanges();
     return RedirectToAction("NewsManager");
 }
예제 #7
0
        public ActionResult AddNews(News model, HttpPostedFileBase file)
        {
            var random = DateHelper.GetTimeStamp();
            var message = "";
            if (file != null)
            {
                string fileName = Path.Combine(Request.MapPath("~/Upload/NewsWord"), random + Path.GetFileName(file.FileName));
                file.SaveAs(fileName);
                NewsWordToHtml(fileName, random);
                message = string.Empty;
                //message = System.IO.File.OpenText(fileName).ReadToEnd();
                var fiepath = Path.Combine(Request.MapPath("~/Upload/NewsWord/" + random), random + ".html");
                using (StreamReader sr = new StreamReader(fiepath, System.Text.Encoding.UTF8))
                {
                    message = sr.ReadToEnd();
                }
                message = BodyFilter.HtmlFilter(message, "/Upload/NewsWord/" + random + "/");
                model.Content = message;

                model.IsWord = true;
            }
            else
            {
                model.IsWord = false;
            }
            model.UserID = CurrentUser.ID;
            model.Time = DateTime.Now;
            model.Browses = 0;
            model.PlaceAsInt = 0;
            model.Priority = 100;

            if (model.IsHaveImg)
            {
                if (file != null)
                {
                    string[] imgs = Helpers.String.GetHtmlImageUrlList(message);
                    model.FirstImgUrl = "/Upload/NewsWord/" + random + "/" + imgs[0];
                }
                else
                {
                    string[] imgs = Helpers.String.GetHtmlImageUrlList(model.Content);
                    model.FirstImgUrl = imgs[0];
                }

            }
            db.News.Add(model);

            db.SaveChanges();
            return RedirectToAction("NewsManager");
        }
예제 #8
0
 public ActionResult SpiderVerify(int id, string Operation, int TypeID)
 {
     var sn = db.SpiderArticles.Find(id);
     if (Operation == "Accept")
     {
         var news = new News
         {
             NewsTypeID = TypeID,
             Browses = 0,
             Place = Place.Native,
             IsWord = false,
             Time = sn.Time,
             Title = sn.Title,
             Content = sn.Content,
             UserID = CurrentUser.ID,
             IsHaveImg = false
         };
         db.News.Add(news);
         sn.NewsID = news.ID;
         sn.Status = SpiderArticleStatus.已收录;
     }
     else
     {
         sn.Status = SpiderArticleStatus.已废弃;
     }
     db.SaveChanges();
     return RedirectToAction("Spider", "Admin");
 }
예제 #9
0
        public ActionResult NewsEdit(News model, HttpPostedFileBase file)
        {
            News news = new News();
            news = db.News.Find(model.ID);
            var random = DateHelper.GetTimeStamp();
            var message = "";
            if (file != null)
            {
                string fileName = Path.Combine(Request.MapPath("~/Upload/NewsWord"), random + Path.GetFileName(file.FileName));
                file.SaveAs(fileName);
                NewsWordToHtml(fileName, random);
                message = string.Empty;
                //message = System.IO.File.OpenText(fileName).ReadToEnd();
                var fiepath = Path.Combine(Request.MapPath("~/Upload/NewsWord/" + random), random + ".html");
                using (StreamReader sr = new StreamReader(fiepath, System.Text.Encoding.UTF8))
                {
                    message = sr.ReadToEnd();
                }
                message = BodyFilter.HtmlFilter(message, "/Upload/NewsWord/" + random + "/");
                news.Content = message;
                news.IsWord = true;
            }
            else
            {
                model.IsWord = false;
                news.Content = model.Content;
            }
            if (model.IsHaveImg)
            {
                if (file != null)
                {
                    string[] imgs = Helpers.String.GetHtmlImageUrlList(message);
                    news.FirstImgUrl = "/Upload/NewsWord/" + random + "/" + imgs[0];
                }
                else
                {
                    string[] imgs = Helpers.String.GetHtmlImageUrlList(model.Content);
                    news.FirstImgUrl = imgs[0];
                }

            }
            news.NewsTypeID = model.NewsTypeID;
            news.Title = model.Title;
            db.SaveChanges();
            return RedirectToAction("NewsManager");
        }