public ActionResult Index(DocumentViewhepler viewHelper)
        {
            
            if (!String.IsNullOrWhiteSpace(viewHelper.KeySearch))
            {
                List<gov_doc_draft> lstResult = new List<gov_doc_draft>();
                var lucene = new LuceneSerives.LuceneDocuments();
                if (viewHelper.TypeSearch == 1)
                {
                    lstResult = lucene.SearchAdvanced(viewHelper.KeySearch, Boolean.TrueString, "doc_full_text").ToList();
                }
                else
                {
                    lstResult = lucene.SearchAdvanced(viewHelper.KeySearch, Boolean.TrueString, "doc_code_and_summany").ToList();
                }

                int totalCount = lstResult.Count;
                viewHelper.TotalCount = totalCount;
                if (totalCount > 0)
                {
                    int totalPage = pageCalculation(totalCount, Constant.limit);
                    viewHelper.TotalPage = totalPage;
                    viewHelper.Page = pageTransition(viewHelper.Direction, viewHelper.Page, totalPage);
                    viewHelper.FirstPage = fistPageCalculation(Constant.maxPageLine, totalPage, viewHelper.Page);
                    viewHelper.LastPage = lastPageCalculation(Constant.maxPageLine, totalPage, viewHelper.Page, viewHelper.FirstPage);
                    int take = Constant.limit;
                    int skip = (viewHelper.Page - 1) * take;
                    viewHelper.LstDocument = lstResult.OrderBy(d => d.score).Skip(skip).Take(take).ToList();
                }
            }
            else
            {
                saveData(viewHelper);
            }

            ViewData["docViewhelper"] = viewHelper;
            return View();
        }
        public ActionResult SaveRegist(gov_doc_draft document)
        {
            if (Session.getCurrentUser() == null)
                return Redirect("/admin/account/logon");
            if (!SercurityServices.HasPermission((int)TypeModule.MODULE_VANBAN, Session.getCurrentUser().username, TypeAudit.Addnew))
            {
                return Redirect("/admin/error/error403");
            }
            if (Request.Files.Count > 0)
            {
                var fileName = string.Empty;
                var file = Request.Files[0];
                var bytes = new byte[file.ContentLength];
                if (bytes.Length > 0)
                {
                    try
                    {
                        file.InputStream.Read(bytes, 0, file.ContentLength);
                        document.attach_file_name = fileName = (file.FileName.IndexOf('\\') != -1 ? file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1) : file.FileName);

                        var fileFolder = fileSaveFolder;
                        var fileDir = Server.MapPath("/") + fileFolder;
                        if (!System.IO.Directory.Exists(fileDir))
                            System.IO.Directory.CreateDirectory(fileDir);
                        var filePath = fileFolder + "\\" + fileName.Substring(0, fileName.LastIndexOf(".")) + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + fileName.Substring(fileName.LastIndexOf("."));
                        System.IO.File.WriteAllBytes(Server.MapPath("/") + filePath, bytes);
                        document.attach_file_path = filePath.Replace("\\", "/");

                    }
                    catch (Exception ex)
                    {
                        TempData["err"] = "Thêm mới thông tin thất bại. Tên File văn bản không được vượt quá 240 ký tự!";
                        return Redirect("Index");
                    }
                }
            }
            try {
                System.IO.TextReader textreader = new IFilter.FilterReader(Server.MapPath("/") + document.attach_file_path);
                string fileContent = textreader.ReadToEnd();
                document.doc_content = fileContent;
            }catch( Exception ex){

            }
            document.entry_username = Session.getCurrentUser().username; ;
            document.entry_datetime = DateTime.Now;
            document.update_username = Session.getCurrentUser().username; ;
            document.update_datetime = DateTime.Now;
            document.doc_type = true;
            try
            {
                document = _cnttDB.gov_doc_draft.Add(document);
                int rs = _cnttDB.SaveChanges();
                var lucene = new LuceneSerives.LuceneDocuments();
                if (rs > 0)
                {
                    lucene.AddUpdateLuceneIndex(document);
                    insertHistory(AccessType.themMoiVanBan, Constant.THEM(Constant.ITEM_VANBAN, Constant.ID, document.id.ToString()));
                    TempData["message"] = Constant.REGIST_SUCCESSFULL;
                }
                else
                {
                    TempData["err"] = Constant.REGIST_ERR;
                }
            }
            catch (Exception ex)
            {
                TempData["err"] = Constant.REGIST_ERR;
            }
            return Redirect("Index");
        }
 public ActionResult Delete(int id)
 {
     if (Session.getCurrentUser() == null)
         return Redirect("/admin/account/logon");
     if (!SercurityServices.HasPermission((int)TypeModule.MODULE_VANBAN, Session.getCurrentUser().username, TypeAudit.Delete))
     {
         return Redirect("/admin/error/error403");
     }
     gov_doc_draft documentInfo = _cnttDB.gov_doc_draft.Find(id);
     if (documentInfo != null)
     {
         try
         {
             _cnttDB.gov_doc_draft.Remove(documentInfo);
             int rs = _cnttDB.SaveChanges();
             if (rs > 0)
             {
                 var lucene = new LuceneSerives.LuceneDocuments();
                 lucene.ClearLuceneIndexRecord(id);
                 insertHistory(AccessType.xoaVanBan, Constant.XOA(Constant.ITEM_VANBAN, Constant.ID, id.ToString()));
                 TempData["message"] = Constant.DELETE_SUCCESSFULL;
             }
             else
             {
                 return Redirect("/admin/error/error404");
             }
         }
         catch (Exception ex)
         {
             return Redirect("/admin/error/error404");
         }
     }
     else
     {
         return Redirect("/admin/error/error405");
     }
     
     
     return Redirect("Index");
 }