예제 #1
0
        /// <summary>
        /// 删除。
        /// </summary>
        /// <param name="id">文档ID。</param>
        /// <returns>父文档页面(如果有父文档)或一览(如果无父文档)。</returns>
        /// <remarks>直接删除。不提示。</remarks>
        public ActionResult Delete(Guid id)
        {
            var db = new Models.Domains.Entities.DMsDbContext();

            var target = db.Documents.Find(id);

            if (target == null)
            {
                return(HttpNotFound());
            }

            var parentDocumentId = target.ParentDocumentId;

            target.ParentDocumentId = null;
            db.SaveChanges();
            db.Documents.Remove(target);
            db.SaveChanges();

            if (parentDocumentId != null)
            {
                return(RedirectToAction("Details", new { id = parentDocumentId }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        //public JsonResult OpenLocalFile(Guid id)
        //{
        //    var folder = "D:\\DocumentLibraries";
        //    var fullFileName = folder + "\\" + id.ToString() + ".pdf";

        //    if (System.IO.File.Exists(fullFileName))
        //    {
        //        //System.Diagnostics.Process.Start(fullFileName);
        //        var process = new System.Diagnostics.Process();
        //        process.StartInfo.FileName = fullFileName;
        //        process.Start();

        //        return Json(new { result = true });
        //    }
        //    else
        //    {
        //        return Json(new { result = false });
        //    }
        //}

        public JsonResult GetChapters(Guid documentId)
        {
            var db     = new Models.Domains.Entities.DMsDbContext();
            var target = db.Documents.Find(documentId);

            if (string.IsNullOrEmpty(target.Url))
            {
                return(Json(false));
            }

            var targetB = new Models.BusinessModels.PageContentSolver.MicrosoftDocsChapters(target.Url, documentId);

            bool result;

            result = targetB.GetPage();
            if (!result)
            {
                return(Json(false));
            }

            result = targetB.ParsePage();
            if (!result)
            {
                return(Json(false));
            }

            target.Chapters.AddRange(targetB.GetChapters());
            target.IsGetAllChapters = true;
            db.SaveChanges();

            return(Json(true));
        }
예제 #3
0
        public ActionResult CreateByUrlMicrosoftDocs([Bind()] Models.ViewModels.Documents.CreateByUrlMicrosoftDocs.CreateByUrlMicrosoftDocs targetV)
        {
            if (ModelState.IsValid)
            {
                //var targetB = new Models.BusinessModels.PageContentSolver.MicrosoftDocs(targetV.Url, targetV.NodeName);
                var targetB = new Models.BusinessModels.PageContentSolver.MicrosoftDocs(targetV);

                bool result;

                result = targetB.GetPage();
                if (!result)
                {
                    return(HttpNotFound());
                }

                result = targetB.ParsePage();
                if (!result)
                {
                    return(HttpNotFound());
                }

                var target = targetB.GetReturn();

                var db = new Models.Domains.Entities.DMsDbContext();

                target.DocumentId       = Guid.NewGuid();
                target.ParentDocumentId = targetV.ParentDocumentId;
                {
                    target.Priority = db.Documents.Where(c => c.ParentDocumentId == targetV.ParentDocumentId).Max(c => c.Priority) + 1;
                    if (target.Priority == null)
                    {
                        target.Priority = 1;
                    }
                }
                target.UpdateTime = DateTime.Now;

                db.Documents.Add(target);
                db.SaveChanges();

                db.Chapters.AddRange(target.Chapters);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = target.DocumentId }));
            }

            return(View(targetV));
        }
예제 #4
0
        /// <summary>
        /// 删除章节。
        /// </summary>
        /// <param name="chapterId">章节ID。</param>
        /// <returns></returns>
        public ActionResult DeleteChapter(Guid chapterId)
        {
            var db = new Models.Domains.Entities.DMsDbContext();

            var target = db.Chapters.Find(chapterId);

            db.Chapters.Remove(target);
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = target.DocumentId }));
        }
        /// <summary>
        /// 设置文档标记。
        /// </summary>
        /// <param name="id">文档ID。</param>
        /// <param name="property">属性名称。</param>
        /// <param name="value">值。</param>
        /// <returns>是否成功执行。</returns>
        public JsonResult SetDocumentFlag(Guid id, string property, bool value)
        {
            var db = new Models.Domains.Entities.DMsDbContext();

            var target = db.Documents.Find(id);

            if (target == null)
            {
                return(Json(new { result = false }));
            }

            switch (property)
            {
            case "IsChecked":
                target.IsChecked = value;
                break;

            case "IsNoted":
                target.IsNoted = value;
                break;

            case "IsGetAllChildren":
                target.IsGetAllChildren = value;
                break;

            case "IsGetAllChapters":
                target.IsGetAllChapters = value;
                break;

            case "IsBookmarked":
                target.IsBookmarked = value;
                break;

            case "IsBook":
                target.IsBook = value;
                break;

            case "IsAbstract":
                target.IsAbstract = value;
                break;

            case "IsMain":
                target.IsMain = value;
                break;

            default:
                return(Json(new { result = false }));
            }
            db.SaveChanges();

            return(GetDocument(id));
        }
예제 #6
0
        public ActionResult CreateChapter([Bind] Models.ViewModels.Documents.CreateChapter.CreateChapter targetV)
        {
            if (ModelState.IsValid)
            {
                var db = new Models.Domains.Entities.DMsDbContext();

                var target = targetV.GetReturn();
                db.Chapters.Add(target);

                db.SaveChanges();

                return(RedirectToAction("Details", new { id = targetV.DocumentId }));
            }

            return(View(targetV));
        }
예제 #7
0
        public ValidateResult Save()
        {
            var target = new Models.Domains.Entities.Document
            {
                DocumentId = Guid.NewGuid(),

                ParentDocumentId = this.ParentDocumentId,

                Title    = this.Title,
                NodeName = this.Title,

                Priority             = this.Priority,
                UpdateTimeForHTTPGet = DateTime.Now,
                IsChecked            = this.IsChecked,

                Url     = this.Url,
                Remarks = this.Remarks,
                IsBook  = true,
                ISBN    = this.ISBN,

                IsAbstract = this.IsBookshelf || this.IsChapterMain,
                IsMain     = this.IsBookRoot || this.IsChapterMain,

                UpdateTime = DateTime.Now
            };

            var db = new Models.Domains.Entities.DMsDbContext();

            lock (Atom.GetInstance())
            {
                if (string.IsNullOrWhiteSpace(this.Title))
                {
                    return(new ValidateResult(false, "Title", "Empty"));
                }
                if (this.Priority < 0)
                {
                    return(new ValidateResult(false, "Priority", "Less Than 0"));
                }

                db.Documents.Add(target);
                db.SaveChanges();
            }

            this.DocumentId = target.DocumentId;

            return(new ValidateResult(true, null));
        }
예제 #8
0
        public ActionResult Edit([Bind()] Models.ViewModels.Documents.Edit.Edit targetV)
        {
            if (ModelState.IsValid)
            {
                var db     = new Models.Domains.Entities.DMsDbContext();
                var target = db.Documents.Find(targetV.DocumentId);

                targetV.GetReturn(target);
                target.UpdateTime = DateTime.Now;

                db.SaveChanges();

                return(RedirectToAction("Details", new { id = target.DocumentId }));
            }

            return(View(targetV));
        }
예제 #9
0
        public ValidateResult Save()
        {
            var db = new Models.Domains.Entities.DMsDbContext();

            lock (Atom.GetInstance())
            {
                var target = db.Documents.Find(this.DocumentId);
                if (target == null)
                {
                    return(new ValidateResult(false, null));
                }

                if (string.IsNullOrWhiteSpace(this.Title))
                {
                    return(new ValidateResult(false, "Title", "Empty"));
                }
                if (this.Priority < 0)
                {
                    return(new ValidateResult(false, "Priority", "Less Than 0"));
                }

                if (System.BitConverter.ToInt64(this.TimeStamp, 0) != System.BitConverter.ToInt64(target.TimeStamp, 0))
                {
                    return(new ValidateResult(false, "TimeStamp", "Changed"));
                }

                target.Title    = this.Title;
                target.NodeName = this.Title;

                target.Priority  = this.Priority;
                target.IsChecked = this.IsChecked;

                target.Url     = this.Url;
                target.Remarks = this.Remarks;
                target.ISBN    = this.ISBN;

                target.IsAbstract = this.IsBookshelf || this.IsChapterMain;
                target.IsMain     = this.IsBookRoot || this.IsChapterMain;

                target.UpdateTime = DateTime.Now;

                db.SaveChanges();
            }

            return(new ValidateResult(true, null));
        }
예제 #10
0
        public ActionResult Create([Bind()] Models.ViewModels.Documents.Create.Create targetV)
        {
            if (string.IsNullOrEmpty(targetV.NodeName))
            {
                targetV.NodeName = targetV.Title;
            }

            if (ModelState.IsValid)
            {
                var target = targetV.GetReturn();

                var db = new Models.Domains.Entities.DMsDbContext();
                db.Documents.Add(target);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = target.DocumentId }));
            }

            return(View(targetV));
        }
예제 #11
0
        public ActionResult CreateByUrlMicrosoftDocsApi(Models.ViewModels.Documents.CreateByUrlMicrosoftDocsApi.CreateByUrlMicrosoftDocsApi targetV)
        {
            var targetB = new Models.BusinessModels.PageContentSolver.MicrosoftDocsApi(targetV.Url, targetV.NodeNameParsingMode);

            bool result;

            result = targetB.GetPage();
            if (!result)
            {
                return(HttpNotFound());
            }

            result = targetB.ParsePage();
            if (!result)
            {
                return(HttpNotFound());
            }

            var target = targetB.GetReturn();

            var db = new Models.Domains.Entities.DMsDbContext();

            target.ParentDocumentId = targetV.ParentDocumentId;
            if (string.IsNullOrEmpty(targetV.NodeNameParsingMode))
            {
                target.NodeName = targetV.NodeName;
            }
            {
                target.Priority = db.Documents.Where(c => c.ParentDocumentId == targetV.ParentDocumentId).Max(c => c.Priority) + 1;
                if (target.Priority == null)
                {
                    target.Priority = 1;
                }
            }

            db.Documents.Add(target);
            db.SaveChanges();

            return(RedirectToAction("Details", new { id = target.DocumentId }));
        }
예제 #12
0
        public ValidateResult Save()
        {
            var db = new Models.Domains.Entities.DMsDbContext();

            lock (Atom.GetInstance())
            {
                var target = db.Documents.Find(this.DocumentId);
                if (target == null)
                {
                    return(new ValidateResult(false, null));
                }

                if (System.BitConverter.ToInt64(this.TimeStamp, 0) != System.BitConverter.ToInt64(target.TimeStamp, 0))
                {
                    return(new ValidateResult(false, "TimeStamp", "Changed"));
                }

                db.Documents.Remove(target);
                db.SaveChanges();
            }

            return(new ValidateResult(true, null));
        }