示例#1
0
        /// <summary>
        /// 获取竞赛列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="passed">是否已过去的竞赛</param>
        /// <returns>竞赛列表</returns>
        public static PagedList <ContestEntity> GetContestList(Int32 pageIndex, Boolean passed)
        {
            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ContestManager.CountContests(passed);

            return(ContestRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, passed)
                   .ToPagedList(pageSize, recordCount));
        }
示例#2
0
        /// <summary>
        /// 获取竞赛列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <returns>竞赛列表</returns>
        public static PagedList <ContestEntity> AdminGetContestList(Int32 pageIndex)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ContestManager.AdminCountContests();

            return(ContestRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount)
                   .ToPagedList(pageSize, recordCount));
        }
示例#3
0
        /// <summary>
        /// 获取竞赛排行Excel文件
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="userrealnames">用户姓名对照表</param>
        /// <returns>竞赛排行</returns>
        public static IMethodResult AdminGetExportRanklist(Int32 cid, String userrealnames)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            ContestEntity contest = ContestManager.GetContest(cid);
            Dictionary <String, String>   userdict    = null;
            Dictionary <String, RankItem> rank        = SolutionRepository.Instance.GetContestRanklist(contest.ContestID, contest.StartTime);
            List <ContestProblemEntity>   problemlist = ContestProblemManager.GetContestProblemList(contest.ContestID);
            List <RankItem> list = new List <RankItem>();

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

            list.Sort();

            if (!String.IsNullOrEmpty(userrealnames))
            {
                userdict = new Dictionary <String, String>();
                String[] nametable = userrealnames.Lines();

                for (Int32 i = 0; i < nametable.Length; i++)
                {
                    if (String.IsNullOrEmpty(nametable[i]))
                    {
                        continue;
                    }

                    String[] namepair = nametable[i].Replace('\t', ' ').Split(' ');

                    if (namepair.Length == 2 && !String.IsNullOrEmpty(namepair[0]) && !String.IsNullOrEmpty(namepair[1]))
                    {
                        userdict.Add(namepair[0], namepair[1]);
                    }
                }
            }

            Byte[] data = ContestResultExport.ExportResultToExcel(contest, problemlist, list, userdict);

            return(MethodResult.SuccessAndLog <Byte[]>(data, "Admin export contest result, id = {0}", cid.ToString()));
        }
示例#4
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> GetForumTopicList(Int32 pageIndex, String cid, String pid)
        {
            ForumTopicType type       = ForumTopicManager.GetForumTopicType(cid, pid);
            Int32          relativeID = ForumTopicManager.GetRelativeID(cid, pid);

            if (type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(relativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(relativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            Int32 pageSize    = ForumTopicManager.FORUM_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.CountForumTopics(cid, pid);

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, type, relativeID, false)
                   .ToPagedList(pageSize, recordCount));
        }
示例#5
0
        /// <summary>
        /// 注册当前用户
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="realName">真实姓名</param>
        /// <returns>是否注册成功</returns>
        public static Boolean RegisterCurrentUser(Int32 cid, String realName)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(realName))
            {
                throw new InvalidInputException("Real Name can not be NULL!");
            }

            if (!String.IsNullOrEmpty(realName) && realName.Length > ContestUserRepository.REALNAME_MAXLEN)
            {
                throw new InvalidInputException("Real Name is too long!");
            }

            ContestEntity contest  = ContestManager.GetRegisterContest(cid);
            String        userName = UserManager.CurrentUserName;

            if (ContestUserRepository.Instance.ExistsEntity(contest.ContestID, userName))
            {
                throw new InvalidInputException("You have already registered this contest!");
            }

            ContestUserEntity entity = new ContestUserEntity()
            {
                ContestID    = contest.ContestID,
                UserName     = userName,
                RealName     = realName,
                IsEnable     = false,
                RegisterTime = DateTime.Now
            };

            return(ContestUserRepository.Instance.InsertEntity(entity) > 0);
        }
示例#6
0
 /// <summary>
 /// 判断给定ID的竞赛是否存在
 /// </summary>
 /// <param name="id">竞赛ID</param>
 /// <returns>竞赛是否存在</returns>
 internal static Boolean InternalExistsContest(Int32 id)
 {
     return(ContestManager.GetContest(id) != null);
 }
示例#7
0
        /// <summary>
        /// 发布新主题
        /// </summary>
        /// <param name="topic">主题实体</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="content">主题帖内容</param>
        /// <param name="postip">发布者IP</param>
        /// <returns>是否成功发布</returns>
        public static Boolean InsertForumTopic(ForumTopicEntity topic, String cid, String pid, String content, String postip)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(topic.Title))
            {
                throw new InvalidInputException("Topic title can not be NULL!");
            }

            if (topic.Title.Length > ForumPostRepository.TITLE_MAXLEN)
            {
                throw new InvalidInputException("Topic title is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(topic.Title))
            {
                throw new InvalidInputException("Topic title can not contain illegal keywords!");
            }

            if (String.IsNullOrEmpty(content) || content.Length < ForumPostRepository.POST_MINLEN)
            {
                throw new InvalidInputException("Topic content is too short!");
            }

            if (content.Length > ForumPostRepository.POST_MAXLEN)
            {
                throw new InvalidInputException("Topic content is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(content))
            {
                throw new InvalidInputException("Topic content can not contain illegal keywords!");
            }

            if (!UserSubmitStatus.CheckLastSubmitForumPostTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit post more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            topic.Type       = ForumTopicManager.GetForumTopicType(cid, pid);
            topic.RelativeID = (topic.Type == ForumTopicType.Default ? 0 : ForumTopicManager.GetRelativeID(cid, pid));

            if (topic.Type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (topic.Type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            topic.UserName = UserManager.CurrentUserName;
            topic.LastDate = DateTime.Now;
            topic.Title    = HtmlEncoder.HtmlEncode(topic.Title);
            content        = HtmlEncoder.HtmlEncode(content);

            Boolean success = ForumTopicRepository.Instance.InsertEntity(topic, content, postip) > 0;

            if (success)
            {
                ForumTopicCache.IncreaseForumTopicCountCache(topic.Type, topic.RelativeID);//更新缓存

                if (topic.Type == ForumTopicType.Problem)
                {
                    ForumTopicCache.IncreaseForumTopicCountCache(ForumTopicType.Default, 0);//更新缓存
                }
            }

            return(success);
        }