/// <summary> /// 根据ID得到一个主题页面实体 /// </summary> /// <param name="name">页面名称</param> /// <returns>主题页面实体</returns> public static TopicPageEntity GetTopicPage(String name) { if (!RegexVerify.IsPageName(name)) { throw new InvalidRequstException(RequestType.TopicPage); } TopicPageEntity topicpage = TopicPageCache.GetTopicPageCache(name);//读取缓存 if (topicpage == null) { topicpage = TopicPageManager.GetReplacedContent(TopicPageRepository.Instance.GetEntity(name)); TopicPageCache.SetTopicPageCache(topicpage);//设置缓存 } if (topicpage == null) { throw new NullResponseException(RequestType.TopicPage); } if (topicpage.IsHide && !AdminManager.HasPermission(PermissionType.SuperAdministrator)) { throw new NoPermissionException(); } return(topicpage); }
/// <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 : ""))); }
/// <summary> /// 根据ID得到一个主题页面实体 /// </summary> /// <param name="id">主题页面ID</param> /// <returns>主题页面实体</returns> public static IMethodResult AdminGetTopicPage(String name) { if (!AdminManager.HasPermission(PermissionType.SuperAdministrator)) { throw new NoPermissionException(); } if (!RegexVerify.IsPageName(name)) { return(MethodResult.InvalidRequest(RequestType.TopicPage)); } TopicPageEntity entity = TopicPageRepository.Instance.GetEntity(name); if (entity == null) { return(MethodResult.NotExist(RequestType.TopicPage)); } return(MethodResult.Success(entity)); }
/// <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)); }