Exemple #1
0
        /// <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()));
        }
        private void RefreshCatalog()
        {
            Thread t = new Thread(() => {
                Invoke(new Action(() =>
                {
                    button_refresh.Enabled = false;
                    progressBar1.Visible   = true;
                    label_progress.Visible = true;
                }));

                _topics = NewsCache.RefreshCatalog(progressBar1, label_progress);

                Invoke(new Action(() =>
                {
                    listView1.Items.Clear();
                    imageList1.Images.Clear();
                    for (int i = 0; i < _topics.Count; i++)
                    {
                        imageList1.Images.Add(_topics[i].Icon);
                        var item        = listView1.Items.Add(_topics[i].Details.name);
                        item.ImageIndex = i;
                        item.SubItems.Add(_topics[i].Details.publisher);
                        item.SubItems.Add(_topics[i].Details.description);
                    }
                    button_refresh.Enabled = true;
                    progressBar1.Visible   = false;
                    label_progress.Visible = false;
                }));
            });

            t.IsBackground = true;
            t.Start();
        }
Exemple #3
0
        /// <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));
        }
Exemple #4
0
        /// <summary>
        /// 获取公告总数(有缓存)
        /// </summary>
        /// <returns>公告总数</returns>
        private static Int32 CountNews()
        {
            Int32 recordCount = NewsCache.GetNewsCountCache();//获取缓存

            if (recordCount < 0)
            {
                recordCount = NewsRepository.Instance.CountEntities() - 1;
                NewsCache.SetNewsCountCache(recordCount);//设置缓存
            }

            return(recordCount);
        }
Exemple #5
0
        /// <summary>
        /// 获取最近公告
        /// </summary>
        /// <param name="count">获取公告数</param>
        /// <returns>最近公告</returns>
        public static List <NewsEntity> GetLastestNewsList()
        {
            List <NewsEntity> list = NewsCache.GetLastestNewsListCache();//获取缓存

            if (list == null)
            {
                list = NewsRepository.Instance.GetLastEntities(HOMEPAGE_PAGE_SIZE);

                NewsCache.SetLastestNewsListCache(list);//设置缓存
            }

            return(list);
        }
Exemple #6
0
        /// <summary>
        /// 根据ID得到一个公告实体
        /// </summary>
        /// <param name="id">公告ID</param>
        /// <returns>公告实体</returns>
        public static NewsEntity GetNews(Int32 id)
        {
            if (id <= 0)
            {
                throw new InvalidRequstException(RequestType.News);
            }

            NewsEntity entity = NewsCache.GetNewsCache(id);//读取缓存

            if (entity == null)
            {
                entity = NewsRepository.Instance.GetEntity(id);
                NewsCache.SetNewsCache(entity);//设置缓存
            }

            if (entity == null)
            {
                throw new NullResponseException(RequestType.News);
            }

            return(entity);
        }
Exemple #7
0
        /// <summary>
        /// 删除指定ID的公告
        /// </summary>
        /// <param name="ids">逗号分隔的公告ID</param>
        /// <returns>是否成功删除</returns>
        public static IMethodResult AdminDeleteNews(String ids)
        {
            if (!AdminManager.HasPermission(PermissionType.NewsManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.News));
            }

            String[] arrids    = ids.Split(',');
            String   defaultID = NewsRepository.DEFAULTID.ToString();

            for (Int32 i = 0; i < arrids.Length; i++)
            {
                if (String.Equals(arrids[i], defaultID))
                {
                    return(MethodResult.FailedAndLog("Can not delete the default news!"));
                }
            }

            Boolean success = NewsRepository.Instance.DeleteEntities(ids) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No news was deleted!"));
            }

            ids.ForEachInIDs(',', id =>
            {
                NewsCache.RemoveNewsCache(id);      //删除缓存
            });
            NewsCache.RemoveLastestNewsListCache(); //删除缓存
            NewsCache.RemoveNewsCountCache();       //删除缓存

            return(MethodResult.SuccessAndLog("Admin delete news, id = {0}", ids));
        }
        /// <summary>
        /// 更新广告Redis
        /// </summary>
        /// <param name="obj">存储到Redis对象</param>
        /// <returns></returns>
        public void SetADSRedis()
        {
            NewsCache fundCache = new NewsCache();

            fundCache.RefreshAdList();
        }