Exemple #1
0
        /// <summary>
        ///载入模板
        /// </summary>
        /// <param name="pageId"></param>
        /// <param name="type"></param>
        /// <param name="refPageId"></param>
        /// <returns></returns>
        public InvokeResult LoadPageTemplate(int pageId, int type, int refPageId, int userId)
        {
            InvokeResult result = new InvokeResult();

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    FileOperationHelper opHelper = new FileOperationHelper();
                    var page = this.FindById(pageId);
                    if (page != null)
                    {
                        if (refPageId != 0)
                        {
                            var pageUpdateBson    = new BsonDocument();
                            var refPageUpdateBson = new BsonDocument();
                            pageUpdateBson.Add("refPageId", refPageId.ToString());
                            var pageResult = this._ctx.Update(page, pageUpdateBson);
                            if (pageResult.Status != Status.Successful)
                            {
                                return(pageResult);
                            }
                            var refPage = this._ctx.FindOneByKeyVal("BookPage", "pageId", refPageId.ToString());
                            if (refPage != null)
                            {
                                refPageUpdateBson.Add("refTimes", refPage.Int("refTimes") + 1);
                                if (type == 1)
                                {
                                    var pageDelResult = opHelper.DeleteFile("BookPage", "pageId", page.Text("pageId"));
                                    if (pageDelResult.Status != Status.Successful)
                                    {
                                        return(pageDelResult);
                                    }
                                }
                                var files = _ctx.FindAllByQueryStr("FileRelation", "tableName=BookPage&keyValue=" + refPageId.ToString()).ToList();
                                //复制文档
                                result = opHelper.CopyFileRelation(files, "BookPage", "pageId", refPageId.ToString());
                                if (result.Status != Status.Successful)
                                {
                                    return(result);
                                }
                            }
                        }
                    }
                    scope.Complete();
                }
                result.Status = Status.Successful;
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }
            return(result);
        }