public ActionResult Edit(FormCollection form)
        {
            TopicPageEntity entity = new TopicPageEntity()
            {
                PageName = form["name"],
                Title = form["title"],
                Description = form["description"],
                Content = form["content"]
            };

            return ResultToMessagePage(TopicPageManager.AdminUpdateTopicPage, entity, form["oldname"], "Your have edited page successfully!");
        }
        public ActionResult Add(FormCollection form)
        {
            TopicPageEntity entity = new TopicPageEntity()
            {
                PageName = form["name"],
                Title = form["title"],
                Description = form["description"],
                Content = form["content"]
            };

            return ResultToMessagePage(TopicPageManager.AdminInsertTopicPage, entity, "Your have added page successfully!");
        }
        /// <summary>
        /// 增加一条主题页面
        /// </summary>
        /// <param name="model">对象实体</param>
        /// <returns>是否成功增加</returns>
        public static IMethodResult AdminInsertTopicPage(TopicPageEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(entity.PageName))
            {
                return MethodResult.InvalidRequest(RequestType.TopicPage);
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return MethodResult.FailedAndLog("Page title can not be NULL!");
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return MethodResult.FailedAndLog("Page description can not be NULL!");
            }

            if (String.IsNullOrEmpty(entity.Content))
            {
                return MethodResult.FailedAndLog("Page content can not be NULL!");
            }

            entity.CreateUser = UserManager.CurrentUserName;
            entity.IsHide = true;
            entity.LastDate = DateTime.Now;

            Boolean success = TopicPageRepository.Instance.InsertEntity(entity) > 0;

            if (!success)
            {
                return MethodResult.FailedAndLog("No page was added!");
            }

            return MethodResult.SuccessAndLog("Admin add page, name = {0}", entity.PageName);
        }
        /// <summary>
        /// 获取替换标签的内容
        /// </summary>
        /// <param name="topicpage">原始内容</param>
        /// <returns>替换标签的内容</returns>
        private static TopicPageEntity GetReplacedContent(TopicPageEntity entity)
        {
            if (entity == null)
            {
                return null;
            }

            entity.Content = entity.Content.Replace("{$Title}", entity.Title);
            entity.Content = entity.Content.Replace("{$Description}", entity.Description);
            entity.Content = entity.Content.Replace("{$CreateUser}", entity.CreateUser);
            entity.Content = entity.Content.Replace("{$LastDate}", entity.LastDate.ToString("yyyy-MM-dd HH:mm:ss"));
            entity.Content = entity.Content.Replace("{$Now}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            return entity;
        }
        /// <summary>
        /// 更新一条主题页面
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <param name="oldname">旧的主题页面名</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateTopicPage(TopicPageEntity entity, String oldname)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(entity.PageName))
            {
                return MethodResult.InvalidRequest(RequestType.TopicPage);
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return MethodResult.FailedAndLog("Page title can not be NULL!");
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return MethodResult.FailedAndLog("Page description can not be NULL!");
            }

            if (String.IsNullOrEmpty(entity.Content))
            {
                return MethodResult.FailedAndLog("Page content can not be NULL!");
            }

            entity.LastDate = DateTime.Now;

            Boolean success = TopicPageRepository.Instance.UpdateEntity(entity, oldname) > 0;

            if (!success)
            {
                return MethodResult.FailedAndLog("No page was updated!");
            }

            TopicPageCache.RemoveTopicPageCache(oldname);//更新缓存

            return MethodResult.SuccessAndLog("Admin update page, name = {0}{1}", entity.PageName,
                (!String.Equals(oldname, entity.PageName, StringComparison.OrdinalIgnoreCase) ? ", previous = " + oldname : ""));
        }
Exemple #6
0
 /// <summary>
 /// 向缓存中写入指定页面信息
 /// </summary>
 /// <param name="topicpage">指定页面信息</param>
 public static void SetTopicPageCache(TopicPageEntity topicpage)
 {
     if (topicpage != null) CacheManager.Set(GetTopicPageCacheKey(topicpage.PageName), topicpage);
 }