Beispiel #1
0
        public ActionResult Add(string Title, string Description, string Category)
        {
            List<Category> categories = bllSession.ICategoryBLL.GetList("").ToList();
            ViewBag.Categories = categories;
            if (ModelState.IsValid)
            {
                try
                {
                    Article article = new Article();
                    article.Browses = 0;
                    article.Time = DateTime.Now;
                    article.Title = Title;
                    article.UserId = CurrentUser.Id;
                    article.Description = Description;
                    article.Category = Category;
                    bllSession.IArticleBLL.Insert(article);
                    return Redirect("/Admin/Blog/Index");
                }
                catch
                {
                    log.Error(new LogContent("增加博文出错", LogType.异常.ToString(), HttpHelper.GetIPAddress()));
                    ModelState.AddModelError("", "增加出现异常");
                }
            }
            else
            {

            }
            return View();
        }
Beispiel #2
0
 public ActionResult Show(int id)
 {
     var article = new Article();
     article = bllSession.IArticleBLL.GetEntity(id);
     article.Browses = article.Browses + 1;
     bllSession.IArticleBLL.Update(article);
     List<Reply> replies = new List<Entity.Reply>();
     replies = bllSession.IReplyBLL.GetList("r.BlogId = " + id).ToList();
     ViewBag.Replies = replies;
     bool result = false;
     //vArticle _article = WordFilterHelper<vArticle>.TextFilter(new vArticle(article), out result) as vArticle;
     return View(new vArticle(article).ToTextFilter(out result));
 }
Beispiel #3
0
        private static void AddToLuceneIndex(Article data, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", data.Id.ToString()));
            writer.DeleteDocuments(searchQuery);

            // add new index entry
            var doc = new Document();
            doc.Add(new Field("Id", data.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Title", data.Title, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Description", data.Description, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Time", data.Time.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Browses", data.Browses.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Category", data.Category, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("UserId", data.UserId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            writer.AddDocument(doc);
        }
Beispiel #4
0
 public static void UpdateLuceneIndex(Article data)
 {
     UpdateLuceneIndex(new[] { data });
 }
Beispiel #5
0
 public ActionResult Edit(int id)
 {
     Article article = new Article();
     article = bllSession.IArticleBLL.GetEntity(id);
     List<Category> categories = bllSession.ICategoryBLL.GetList("").ToList();
     ViewBag.Categories = categories;
     return View(article);
 }
Beispiel #6
0
 /// <summary>
 /// 后台博文预览
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult Show(int id)
 {
     Article article = new Article();
     article = bllSession.IArticleBLL.GetEntity(id);
     return View(new vArticle(article));
 }
Beispiel #7
0
 public ActionResult Edit(Article model)
 {
     Article _article = new Article();
     _article = bllSession.IArticleBLL.GetEntity(model.Id);
     List<Category> categories = bllSession.ICategoryBLL.GetList("").ToList();
     ViewBag.Categories = categories;
     if (ModelState.IsValid)
     {
         try
         {
             Article article = new Article();
             article = bllSession.IArticleBLL.GetEntity(model.Id);
             article.Category = model.Category;
             article.Title = model.Title;
             article.Description = model.Description;
             bool result = bllSession.IArticleBLL.Update(article);
             if (result)
             {
                 return Redirect("/Admin/Blog/Show/" + model.Id);
             }
             else
             {
                 log.Error(new LogContent(_article.Title +"修改博文出错", LogType.异常.ToString(), HttpHelper.GetIPAddress()));
                 ModelState.AddModelError("", "修改博文出错");
             }
         }
         catch
         {
             log.Error(new LogContent(_article.Title+"修改博文出错", LogType.异常.ToString(), HttpHelper.GetIPAddress()));
             ModelState.AddModelError("", "修改博文出错");
         }
     }
     else
     {
         ModelState.AddModelError("", "填写数据有误");
     }
     return View(_article);
 }