public ActionResult EditArticelInfo(Articel articelInfo)
        {
            var articel = ArticelService.LoadEntities(a => a.ID == articelInfo.ID).FirstOrDefault();

            articel.ArticleContent = articelInfo.ArticleContent;
            articel.Author         = articelInfo.Author;
            articel.FullTitle      = articelInfo.FullTitle;
            articel.ModifyDate     = DateTime.Now;
            articel.Intro          = articelInfo.Intro;
            articel.KeyWords       = articelInfo.KeyWords;
            articel.Origin         = articelInfo.Origin;
            articel.PhotoUrl       = articelInfo.PhotoUrl;
            articel.Title          = articelInfo.Title;
            articel.TitleFontColor = articelInfo.TitleFontColor;
            articel.TitleFontType  = articelInfo.TitleFontType;
            articel.TitleType      = articelInfo.TitleType;
            if (ArticelService.EditEntity(articel))
            {
                CreateHtmlPage(articel, "edit");
                return(Content("ok"));
            }
            else
            {
                return(Content("no"));
            }
        }
        public void Delete(Articel al)
        {
            Articel articel = _db.Articels.Find(al.ArticelID);

            _db.Articels.Remove(articel);
            _db.SaveChanges();
        }
示例#3
0
 public IActionResult Edit(Articel al)
 {
     if (ModelState.IsValid)
     {
         al.Posted = DateTime.Now;
         articelRepository.Update(al);
         return(RedirectToAction("Index"));
     }
     return(View(al));
 }
示例#4
0
        /// <summary>
        /// 加载相关新闻
        /// </summary>
        /// <returns></returns>
        public ActionResult LoadLikeNews()
        {
            int     id          = int.Parse(Request["articelId"]);
            Articel article     = ArticelBLL.LoadEntity(a => a.ID == id).FirstOrDefault();
            var     articleList = (from a in article.ArticelClass
                                   from b in a.Articel
                                   where b.ID != id
                                   select b).OrderBy(a => a.ID).Skip(0).Take(4);
            var temp = from a in articleList
                       select new { Id = a.ID, Title = a.Title, AddDate = a.AddDate };

            return(Content(SerializeHelper.SerializeToString(temp)));
        }
示例#5
0
 public IActionResult Create(Articel al)
 {
     if (ModelState.IsValid)
     {
         al.Posted = DateTime.Now;
         articelRepository.Create(al);
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
示例#6
0
        /// <summary>
        /// 静态化页面
        /// </summary>
        /// <returns></returns>
        public void StaticPage(Articel article)
        {
            string   htmlFile = Common.NVelocityHelper.RenderTemplate("ArticelTemplateInfo", article, "/ArticelTemplate/");
            DateTime addDate  = article.AddDate;
            string   dir      = "/ArticelHtml/" + addDate.Year + "/" + addDate.Month + "/" + addDate.Day + "/";

            if (!Directory.Exists(Server.MapPath(dir)))
            {
                Directory.CreateDirectory(Server.MapPath(dir));
            }
            string fulePath = dir + article.ID + ".html";

            System.IO.File.WriteAllText(Server.MapPath(fulePath), htmlFile);
        }
        /// <summary>
        /// 生成静态页
        /// </summary>
        /// <param name="articelInfo"></param>
        /// <param name="flag"></param>
        public void CreateHtmlPage(Articel articelInfo, string flag)
        {
            string html = NVelocityHelper.RenderTemplate("ArticelTemplateInfo", articelInfo, "/ArticelTemplate/");
            string dir  = "/ArticelHtml/" + articelInfo.AddDate.Year + "/" + articelInfo.AddDate.Month + "/" + articelInfo.AddDate.Day + "/";

            if (flag == "add")
            {
                //dir = "/ArticelHtml/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/";
                Directory.CreateDirectory(Path.GetDirectoryName(Request.MapPath(dir)));
            }
            //else
            //{
            //    dir = "/ArticelHtml/" + articelInfo.AddDate.Year + "/" + articelInfo.AddDate.Month + "/" + articelInfo.AddDate.Day + "/";
            //}

            string fullDir = dir + articelInfo.ID + ".html";

            System.IO.File.WriteAllText(Request.MapPath(fullDir), html, System.Text.Encoding.UTF8);
        }
        public ActionResult AddArticelInfo(Articel articelInfo)
        {
            articelInfo.AddDate    = DateTime.Now;
            articelInfo.DelFlag    = 0;
            articelInfo.ModifyDate = DateTime.Now;
            int cid = int.Parse(Request["ArticelClassInfo"]);

            ArticelService.AddEntity(cid, articelInfo);
            //完成内容保存以后,生成静态页面
            CreateHtmlPage(articelInfo, "add");
            //将新添加的文章写到队列中并且存储到Lucene.Net中
            SearchContent searchContent = new SearchContent();

            searchContent.Content = articelInfo.ArticleContent;
            searchContent.Id      = articelInfo.ID;
            searchContent.Flag    = 0;
            searchContent.AddDate = articelInfo.AddDate;
            searchContent.Title   = articelInfo.Title;
            IndexManager.GetInstance().AddEqueue(searchContent);
            return(Content("ok"));
        }
示例#9
0
        public IActionResult Details(int id)
        {
            Articel al = articelRepository.Get(id);

            return(View(al));
        }
示例#10
0
        public IActionResult Delete(Articel al)
        {
            articelRepository.Delete(al);

            return(RedirectToAction("Index"));
        }
示例#11
0
 public void Update(Articel al)
 {
     _db.Articels.Update(al);
     _db.SaveChanges();
 }
示例#12
0
        public Articel Get(int id)
        {
            Articel al = _db.Articels.Find(id);

            return(al);
        }
示例#13
0
 public void Create(Articel al)
 {
     _db.Articels.Add(al);
     _db.SaveChanges();
 }