public ActionResult Add(FormCollection form) { NewsEntity entity = new NewsEntity() { Title = form["title"], Description = form["description"] }; return ResultToMessagePage(NewsManager.AdminInsertNews, entity, "Your have added news successfully!"); }
public ActionResult Edit(Int32 id, FormCollection form) { NewsEntity entity = new NewsEntity() { AnnounceID = id, Title = form["title"], Description = form["description"] }; return ResultToMessagePage(NewsManager.AdminUpdateNews, entity, "Your have edited news successfully!"); }
/// <summary> /// 向缓存中写入指定公告信息 /// </summary> /// <param name="news">指定公告信息</param> public static void SetNewsCache(NewsEntity news) { if (news != null) CacheManager.Set(GetNewsCacheKey(news.AnnounceID), news); }
/// <summary> /// 更新一条公告 /// </summary> /// <param name="entity">对象实体</param> /// <returns>是否成功更新</returns> public static IMethodResult AdminUpdateNews(NewsEntity entity) { if (!AdminManager.HasPermission(PermissionType.NewsManage)) { throw new NoPermissionException(); } if (String.IsNullOrEmpty(entity.Title)) { return MethodResult.FailedAndLog("News title can not be NULL!"); } if (String.IsNullOrEmpty(entity.Description)) { return MethodResult.FailedAndLog("News content can not be NULL!"); } entity.PublishDate = DateTime.Now; Boolean success = NewsRepository.Instance.UpdateEntity(entity) > 0; if (!success) { return MethodResult.FailedAndLog("No news was updated!"); } NewsCache.SetNewsCache(entity);//更新缓存 if (entity.AnnounceID != NewsRepository.DEFAULTID) { NewsCache.RemoveLastestNewsListCache();//删除缓存 } return MethodResult.SuccessAndLog("Admin update news, id = {0}", entity.AnnounceID.ToString()); }
/// <summary> /// 增加一条公告 /// </summary> /// <param name="entity">对象实体</param> /// <returns>是否成功增加</returns> public static IMethodResult AdminInsertNews(NewsEntity entity) { if (!AdminManager.HasPermission(PermissionType.NewsManage)) { throw new NoPermissionException(); } if (String.IsNullOrEmpty(entity.Title)) { return MethodResult.FailedAndLog("News title can not be NULL!"); } if (String.IsNullOrEmpty(entity.Description)) { return MethodResult.FailedAndLog("News content can not be NULL!"); } entity.PublishDate = DateTime.Now; Boolean success = NewsRepository.Instance.InsertEntity(entity) > 0; if (!success) { return MethodResult.FailedAndLog("No news was added!"); } NewsCache.RemoveLastestNewsListCache();//删除缓存 NewsCache.RemoveNewsCountCache();//删除缓存 return MethodResult.SuccessAndLog("Admin add news, title = {0}", entity.Title); }