Ejemplo n.º 1
0
        /// <summary>
        /// 根据ID得到一个竞赛实体
        /// </summary>
        /// <param name="id">竞赛ID</param>
        /// <returns>竞赛实体</returns>
        public static ContestEntity GetContest(Int32 id)
        {
            if (id < ContestRepository.NONECONTEST)
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            ContestEntity contest = ContestCache.GetContestCache(id);//获取缓存

            if (contest == null)
            {
                contest = ContestRepository.Instance.GetEntity(id);
                ContestCache.SetContestCache(contest);//设置缓存
            }

            if (contest == null)
            {
                throw new NullResponseException(RequestType.Contest);
            }

            if (contest.IsHide && !AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException("You have no privilege to view the contest!");
            }

            return(contest);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新竞赛隐藏状态
        /// </summary>
        /// <param name="ids">竞赛ID列表</param>
        /// <param name="isHide">隐藏状态</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContestIsHide(String ids, Boolean isHide)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

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

            Boolean success = ContestRepository.Instance.UpdateEntityIsHide(ids, isHide) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No contest was {0}!", isHide ? "hided" : "unhided"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ContestCache.RemoveContestCache(id);//删除缓存
            });

            ContestCache.RemoveContestListCountCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin {1} contest, id = {0}", ids, isHide ? "hide" : "unhide"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新竞赛信息
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContest(ContestEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Contest title cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("Contest description cannot be NULL!"));
            }

            if (entity.StartTime >= entity.EndTime)
            {
                return(MethodResult.FailedAndLog("Start time must be less than end time!"));
            }

            if (entity.ContestType == ContestType.RegisterPrivate || entity.ContestType == ContestType.RegisterPublic)
            {
                if (!entity.RegisterStartTime.HasValue || !entity.RegisterEndTime.HasValue)
                {
                    return(MethodResult.FailedAndLog("Register time cannot be NULL!"));
                }

                if (entity.RegisterStartTime >= entity.RegisterEndTime)
                {
                    return(MethodResult.FailedAndLog("Register start time must be less than register end time!"));
                }

                if (entity.RegisterEndTime >= entity.StartTime)
                {
                    return(MethodResult.FailedAndLog("Register end time must be less than contest start time!"));
                }
            }

            entity.LastDate = DateTime.Now;

            Boolean success = ContestRepository.Instance.UpdateEntity(entity) > 0;

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

            ContestCache.RemoveContestCache(entity.ContestID); //删除缓存
            ContestCache.RemoveContestListCountCache();        //删除缓存

            return(MethodResult.SuccessAndLog("Admin update contest, id = {0}", entity.ContestID.ToString()));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取公告总数(有缓存)
        /// </summary>
        /// <param name="passed">是否已过去的竞赛</param>
        /// <returns>竞赛总数</returns>
        public static Int32 CountContests(Boolean passed)
        {
            Int32 recordCount = ContestCache.GetContestListCountCache(passed);//获取缓存

            if (recordCount < 0)
            {
                recordCount = ContestRepository.Instance.CountEntities(passed);
                ContestCache.SetContestListCountCache(passed, recordCount);//设置缓存
            }

            return(recordCount);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取竞赛排行
        /// </summary>
        /// <param name="entity">竞赛实体</param>
        /// <returns>竞赛排行</returns>
        public static List <RankItem> GetContestRanklist(ContestEntity entity)
        {
            List <RankItem> list = ContestCache.GetContestRankCache(entity.ContestID);

            if (list == null)
            {
                list = new List <RankItem>();
                Dictionary <String, RankItem> rank = SolutionRepository.Instance.GetContestRanklist(entity.ContestID, entity.StartTime);

                foreach (RankItem userRank in rank.Values)
                {
                    list.Add(userRank);
                }

                list.Sort();

                ContestCache.SetContestRankCache(entity.ContestID, list);
            }

            return(list);
        }