示例#1
0
        /// <summary>
        /// 删除Books表信息时 添加删除索引请求至队列
        /// </summary>
        /// <param name="bid"></param>
        //public void Del(int bid) {
        //    BookViewMode bvm = new BookViewMode();
        //    bvm.Id = bid;
        //    bvm.IT = IndexType.Delete;
        //    bookQueue.Enqueue(bvm);
        //}
        /// <summary>
        /// 修改Books表信息时 添加修改索引(实质上是先删除原有索引 再新增修改后索引)请求至队列
        /// </summary>
        /// <param name="books"></param>
        public void Mod(ReleaseForumModel model)
        {
            ReleaseForumModel bvm = new ReleaseForumModel();

            bvm.ForumName    = model.ForumName;
            bvm.ForumContent = model.ForumContent;
            bvm.ForumLogo    = model.ForumLogo;
            bvm.ForumTypeID  = model.ForumTypeID;
            bookQueue.Enqueue(bvm);
        }
        public ActionResult ReleaseForum(ReleaseForumModel model)
        {
            try
            {
                var perentList = ForumTypeSiteContract.ForumTypes.ToList();

                if (perentList.Count > 0)
                {
                    foreach (var item in perentList)
                    {
                        ForumTypeView ForumTypeModel = new ForumTypeView
                        {
                            ForumTypeID       = item.Id,
                            ForumTypeName     = item.ForumTypeName,
                            ForumParentTypeID = item.ForumParentTypeID,
                            ForumTypeLogo     = imgurl
                        };
                        ForumTypeView.Add(ForumTypeModel);
                    }
                }
                List <SelectListItem> SelectItems = new List <SelectListItem>();
                foreach (ForumTypeView forumType in ForumTypeView)
                {
                    SelectListItem item = new SelectListItem();
                    item.Text     = forumType.ForumTypeName;
                    item.Value    = forumType.ForumTypeID.ToString();
                    item.Selected = false;
                    SelectItems.Add(item);
                }
                ViewData["ForumTypeID"] = SelectItems;
                model.ForumTypeID       = Convert.ToInt32(Request["ForumTypeID"]);
                model.ForumLogo         = imgurl;
                IndexManager.bookIndex.Mod(model);
                OperationResult result = ForumModuleSiteContract.ReleaseFroum(model);
                string          msg    = result.Message ?? result.ResultType.ToDescription();
                if (result.ResultType == OperationResultType.Success)
                {
                    return(RedirectToAction("ReleaseForum", "ForumModule"));
                }

                ModelState.AddModelError("", msg);
                return(View());
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(View());
            }
        }
        public ActionResult ReleaseForum()
        {
            string returnUrl = Request.Params["returnUrl"];

            returnUrl = returnUrl ?? Url.Action("ReleaseForum", "ForumModule");
            var perentList = ForumTypeSiteContract.ForumTypes.ToList();

            if (perentList.Count > 0)
            {
                foreach (var item in perentList)
                {
                    ForumTypeView ForumTypeModel = new ForumTypeView
                    {
                        ForumTypeID       = item.Id,
                        ForumTypeName     = item.ForumTypeName,
                        ForumParentTypeID = item.ForumParentTypeID,
                        ForumTypeLogo     = item.ForumTypeLogo
                    };
                    ForumTypeView.Add(ForumTypeModel);
                }
            }


            //为前台页面DropDownList准备的数据
            List <SelectListItem> SelectItems = new List <SelectListItem>();

            SelectItems.Add(new SelectListItem()
            {
                Text = "请选择", Value = "-1", Selected = true
            });

            foreach (ForumTypeView forumType in ForumTypeView)
            {
                SelectListItem item = new SelectListItem();
                item.Text     = forumType.ForumTypeName;
                item.Value    = forumType.ForumTypeID.ToString();
                item.Selected = false;
                SelectItems.Add(item);
            }
            ViewData["ForumTypeID"] = SelectItems;
            ReleaseForumModel model = new ReleaseForumModel
            {
                ReturnUrl = returnUrl,
            };

            return(View(model));
        }
示例#4
0
        public OperationResult ReleaseFroum(ReleaseForumModel model)
        {
            if (Session["SystemUser"] == "" || Session["SystemUser"] == null)
            {
                return(new OperationResult(OperationResultType.PurviewLack, "登陆后,方可发布帖子!"));
            }
            PublicHelper.CheckArgument(model, "model");
            Forum releaseForum = new Forum
            {
                ForumName    = model.ForumName,
                ForumContent = model.ForumContent,
                ForumLogo    = model.ForumLogo,
                ForumTypeID  = model.ForumTypeID,
                SystemUserID = ((SystemUser)Session["SystemUser"]).Id
            };
            OperationResult result = base.ReleaseForum(releaseForum);

            return(result);
        }
示例#5
0
        /// <summary>
        /// 更新索引库操作
        /// </summary>
        private void CRUDIndex()
        {
            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NativeFSLockFactory());
            bool        isExist   = IndexReader.IndexExists(directory);

            if (isExist)
            {
                if (IndexWriter.IsLocked(directory))
                {
                    IndexWriter.Unlock(directory);
                }
            }
            IndexWriter writer = new IndexWriter(directory, new PanGuAnalyzer(), !isExist, IndexWriter.MaxFieldLength.UNLIMITED);

            while (bookQueue.Count > 0)
            {
                Document          document = new Document();
                ReleaseForumModel model    = bookQueue.Dequeue();
                //if(book.IT == IndexType.Insert) {
                //    document.Add(new Field("id", book.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                //    document.Add(new Field("ForumName", book.ForumName, Field.Store.YES, Field.Index.ANALYZED,
                //                           Field.TermVector.WITH_POSITIONS_OFFSETS));
                //    document.Add(new Field("ForumContent", book.ForumContent, Field.Store.YES, Field.Index.ANALYZED,
                //                           Field.TermVector.WITH_POSITIONS_OFFSETS));
                //    writer.AddDocument(document);
                //} else if(book.IT == IndexType.Delete) {
                //    writer.DeleteDocuments(new Term("id", book.Id.ToString()));
                //} else if(book.IT == IndexType.Modify) {
                //    //先删除 再新增
                //    writer.DeleteDocuments(new Term("id", book.Id.ToString()));
                document.Add(new Field("ForumTypeID", model.ForumTypeID.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                document.Add(new Field("ForumName", model.ForumName, Field.Store.YES, Field.Index.ANALYZED,
                                       Field.TermVector.WITH_POSITIONS_OFFSETS));
                document.Add(new Field("ForumContent", model.ForumContent, Field.Store.YES, Field.Index.ANALYZED,
                                       Field.TermVector.WITH_POSITIONS_OFFSETS));
                writer.AddDocument(document);
            }
            writer.Close();
            directory.Close();
        }