/// <summary>
        /// 更新页面版本
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public InvokeResult RecoveryBodyVersion(int Id, int sysUserId)
        {
            InvokeResult result = new InvokeResult()
            {
                Status = Status.Successful
            };
            PageBodyBll bodyBll  = PageBodyBll._(this._ctx);
            BookPageBll pageBll  = BookPageBll._(this._ctx);
            var         bVersion = FindById(Id);
            var         Page     = bVersion.SourceBson("pageId");

            if (bVersion != null && Page != null)
            {
                var currentBody = Page.ChildBsonList("PageBody").FirstOrDefault();
                //currentBody.lastVersion = currentBody.lastVersion + 1;
                if (currentBody == null)
                {
                    result.Status  = Status.Failed;
                    result.Message = "该对象被删除,请刷新后重试";
                    return(result);
                }
                var currentBodyUpdateBson = new BsonDocument();
                currentBodyUpdateBson.Add("body", bVersion.Text("body"));
                currentBodyUpdateBson.Add("lastVersion", currentBody.Int("lastVersion") + 1);
                var newBodyVersion = new BsonDocument();
                newBodyVersion.Add("body", bVersion.Text("body"));
                newBodyVersion.Add("userId", sysUserId);
                newBodyVersion.Add("bodyVersion", currentBody.Int("lastVersion") + 1);
                newBodyVersion.Add("bodyId", bVersion.Text("bodyId"));
                this._ctx.Update(Page, string.Format("lastVersion={0}", currentBody.Int("lastVersion") + 1));
                using (TransactionScope tran = new TransactionScope())
                {
                    var draft = Page.ChildBsonList("PageTempBody").Where(r => r.Int("saveUserId") == sysUserId).FirstOrDefault();
                    if (draft != null)
                    {
                        var delRet = this._ctx.Delete("PageTempBody", string.Format("tempBodyId={0}", draft.Text("tempBodyId")));
                    }
                    result = this._ctx.Insert("PageBodyVersion", newBodyVersion);
                    result = bodyBll.Update(currentBody, currentBodyUpdateBson);

                    tran.Complete();
                }
                try
                {
                    pageBll.GenerateSnapshot(Page.Int("pageId"));
                    //pageBll.BuildIndex(Page);
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                result.Status  = Status.Failed;
                result.Message = "该版本可能已经被刷新请重新刷新!";
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 获取最新版本的页面内容
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public string GetLastestPageBody(BsonDocument page)
        {
            PageBodyBll bodyBll = PageBodyBll._();

            if (page == null)
            {
                return(string.Empty);
            }
            var Body = bodyBll.FindLatestVersionByPageId(page.Int("pageId"), page.Int("lastVersion"));

            if (Body != null)
            {
                return(Body.Text("body").Trim());
            }
            return(string.Empty);
        }