Exemple #1
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"));
        }
Exemple #2
0
        /// <summary>
        /// 更新题目隐藏状态
        /// </summary>
        /// <param name="ids">题目ID列表</param>
        /// <param name="isHide">隐藏状态</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblemIsHide(String ids, Boolean isHide)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

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

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

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

            ids.ForEachInIDs(',', id =>
            {
                ProblemCache.RemoveProblemCache(id);                         //删除缓存
                ProblemCache.RemoveProblemSetCache(GetProblemPageIndex(id)); //删除缓存
            });

            return(MethodResult.SuccessAndLog("Admin {1} problem, id = {0}", ids, isHide ? "hide" : "unhide"));
        }
        /// <summary>
        /// 获取帖子列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="fpids">帖子ID列表</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖用户名</param>
        /// <param name="title">帖子标题</param>
        /// <param name="content">帖子内容</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <param name="postip">发帖IP</param>
        /// <returns>帖子列表</returns>
        public static PagedList <ForumPostEntity> AdminGetForumPostList(Int32 pageIndex, String fpids, String ftids, String username, String title, String content, String isHide, String startDate, String endDate, String postip)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumPostManager.AdminCountForumPosts(fpids, ftids, username, title, content, isHide, startDate, endDate, postip);

            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            fpids = fpids.SearchOptimized();
            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(fpids) && !RegexVerify.IsNumericIDs(fpids))
            {
                throw new InvalidRequstException(RequestType.ForumPost);
            }

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            return(ForumPostRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount,
                                fpids, ftids, username, title, content,
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()), postip)
                   .ToPagedList(pageSize, recordCount));
        }
Exemple #4
0
        /// <summary>
        /// 获取主题总数(无缓存)
        /// </summary>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>主题总数</returns>
        private static Int32 AdminCountForumTopics(String ftids, String username, String title, String type, String relativeID, String isLocked, String isHide, String startDate, String endDate)
        {
            Byte     topictype = 0;
            Int32    rid = -1;
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            if (!String.IsNullOrEmpty(relativeID) && !Int32.TryParse(relativeID, out rid))
            {
                throw new InvalidInputException("Relative ID is INVALID!");
            }

            return(ForumTopicRepository.Instance
                   .CountEntities(ftids, username, title,
                                  (!String.IsNullOrEmpty(type) && Byte.TryParse(type, out topictype) ? (ForumTopicType)topictype : new Nullable <ForumTopicType>()), rid,
                                  (!String.IsNullOrEmpty(isLocked) ? "1".Equals(isLocked, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                  (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                  (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                  (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>())));
        }
Exemple #5
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> AdminGetForumTopicList(Int32 pageIndex, String ftids, String username, String title, String type, String relativeID, String isLocked, String isHide, String startDate, String endDate)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.AdminCountForumTopics(ftids, username, title, type, relativeID, isLocked, isHide, startDate, endDate);

            Byte     topictype = 0;
            Int32    rid = -1;
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            if (!String.IsNullOrEmpty(relativeID) && !Int32.TryParse(relativeID, out rid))
            {
                throw new InvalidInputException("Relative ID is INVALID!");
            }

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, ftids, username, title,
                                (!String.IsNullOrEmpty(type) && Byte.TryParse(type, out topictype) ? (ForumTopicType)topictype : new Nullable <ForumTopicType>()), rid,
                                (!String.IsNullOrEmpty(isLocked) ? "1".Equals(isLocked, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()))
                   .ToPagedList(pageSize, recordCount));
        }
Exemple #6
0
        /// <summary>
        /// 更新主题锁定状态
        /// </summary>
        /// <param name="ids">主题ID列表</param>
        /// <param name="isLock">是否锁定</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateForumTopicIsLocked(String ids, Boolean isLocked)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

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

            Boolean success = ForumTopicRepository.Instance.UpdateEntityIsLocked(ids, isLocked) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No forum topic was {0}!", isLocked ? "locked" : "unlocked"));
            }

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

            return(MethodResult.SuccessAndLog("Admin {1} forum topic, id = {0}", ids, isLocked ? "lock" : "unlock"));
        }
Exemple #7
0
        /// <summary>
        /// 根据题目搜索结果获取题目列表
        /// </summary>
        /// <param name="type">搜索类别</param>
        /// <param name="content">搜索内容</param>
        /// <returns>题目列表</returns>
        public static List <ProblemEntity> GetProblemBySearch(String type, String content)
        {
            List <ProblemEntity> list = null;

            if (String.Equals(type, "category", StringComparison.OrdinalIgnoreCase))
            {
                Int32 typeID = -1;

                if (!Int32.TryParse(content, out typeID) || typeID <= 0)
                {
                    throw new InvalidRequstException(RequestType.ProblemCategory);
                }

                list = ProblemManager.GetProblemListByType(typeID);
            }
            else if (String.Equals(type, "pid", StringComparison.OrdinalIgnoreCase))
            {
                content = content.SearchOptimized();

                if (!RegexVerify.IsNumericIDs(content))
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                list = ProblemManager.GetProblemListByID(content);
            }
            else if (String.Equals(type, "title", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrEmpty(content) || !SQLValidator.IsNonNullANDSafe(content))
                {
                    throw new InvalidInputException("Problem Title is INVALID!");
                }

                list = ProblemManager.GetProblemListByTitle(content);
            }
            else if (String.Equals(type, "source", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrEmpty(content) || !SQLValidator.IsNonNullANDSafe(content))
                {
                    throw new InvalidInputException("Problem Source is INVALID!");
                }

                list = ProblemManager.GetProblemListBySource(content);
            }

            list = GetUserCanViewProblemList(list);

            return(list);
        }
Exemple #8
0
        /// <summary>
        /// 删除指定ID的邮件
        /// </summary>
        /// <param name="ids">逗号分隔的邮件ID</param>
        /// <returns>是否成功删除</returns>
        public static Boolean DeleteUserMails(String ids)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                throw new InvalidRequstException(RequestType.UserMail);
            }

            String  userName = UserManager.CurrentUserName;
            Boolean success  = UserMailRepository.Instance.DeleteEntities(userName, ids) > 0;

            if (success)
            {
                UserMailCache.RemoveUserUnReadMailCountCache(userName);//删除缓存
            }

            return(success);
        }
Exemple #9
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>
        /// 获取帖子总数(无缓存)
        /// </summary>
        /// <param name="fpids">帖子ID列表</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖用户名</param>
        /// <param name="title">帖子标题</param>
        /// <param name="content">帖子内容</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <param name="postip">发帖IP</param>
        /// <returns>帖子总数</returns>
        private static Int32 AdminCountForumPosts(String fpids, String ftids, String username, String title, String content, String isHide, String startDate, String endDate, String postip)
        {
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            fpids = fpids.SearchOptimized();
            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(fpids) && !RegexVerify.IsNumericIDs(fpids))
            {
                throw new InvalidRequstException(RequestType.ForumPost);
            }

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            return(ForumPostRepository.Instance
                   .CountEntities(fpids, ftids, username, title, content,
                                  (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                  (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                  (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()), postip));
        }
Exemple #11
0
        private static Boolean AdminGetSolutionParams(String sids, String cid, String pid, String name, String lang, String type, String startDate, String endDate,
                                                      out String solutionIDs, out Int32 problemID, out Int32 contestID, out String userName, out LanguageType languageType, out ResultType?resultType, out DateTime?dtStart, out DateTime?dtEnd)
        {
            Boolean noCondition = true;
            String  dateFormat  = "yyyy-MM-dd HH:mm:ss";

            solutionIDs  = String.Empty;
            contestID    = -1;
            problemID    = -1;
            userName     = String.Empty;
            languageType = LanguageType.Null;
            resultType   = new Nullable <ResultType>();
            dtStart      = null;
            dtEnd        = null;

            if (!String.IsNullOrEmpty(sids))
            {
                solutionIDs = sids.SearchOptimized();

                if (!RegexVerify.IsNumericIDs(solutionIDs))
                {
                    throw new InvalidRequstException(RequestType.Solution);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(cid))
            {
                if (!Int32.TryParse(cid, out contestID))
                {
                    throw new InvalidRequstException(RequestType.Contest);
                }

                if (contestID < ContestRepository.NONECONTEST)
                {
                    throw new InvalidRequstException(RequestType.Contest);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(pid))
            {
                if (!Int32.TryParse(pid, out problemID))
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                if (problemID < ConfigurationManager.ProblemSetStartID)
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(name))
            {
                if (!RegexVerify.IsUserName(name))
                {
                    throw new InvalidRequstException(RequestType.User);
                }

                userName    = name;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(lang))
            {
                Byte langType = Byte.MaxValue;

                if (!Byte.TryParse(lang, out langType))
                {
                    throw new InvalidInputException("Language Type is INVALID!");
                }

                languageType = LanguageType.FromLanguageID(langType);
                noCondition  = false;
            }

            if (!String.IsNullOrEmpty(type))
            {
                Byte resType = Byte.MaxValue;

                if (!Byte.TryParse(type, out resType))
                {
                    throw new InvalidInputException("Result Type is INVALID!");
                }

                resultType  = (ResultType)resType;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(startDate))
            {
                DateTime temp;
                if (!DateTime.TryParseExact(startDate, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    throw new InvalidInputException("Datetime is INVALID!");
                }

                dtStart     = temp;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(endDate))
            {
                DateTime temp;
                if (!DateTime.TryParseExact(endDate, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    throw new InvalidInputException("Datetime is INVALID!");
                }

                dtEnd = temp;

                if (dtStart.HasValue && dtStart.Value >= dtEnd.Value)
                {
                    throw new InvalidInputException("Start date CANNOT be later than end date!");
                }

                noCondition = false;
            }

            return(noCondition);
        }
Exemple #12
0
        /// <summary>
        /// 设置指定ID的题目类型对
        /// </summary>
        /// <param name="problemID">题目ID</param>
        /// <param name="sourceIDs">旧逗号分隔的题目类型ID</param>
        /// <param name="targetIDs">新逗号分隔的题目类型ID</param>
        /// <returns>是否成功设置</returns>
        public static IMethodResult AdminUpdateProblemCategoryItems(Int32 problemID, String sourceIDs, String targetIDs)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (problemID < ConfigurationManager.ProblemSetStartID)
            {
                return(MethodResult.InvalidRequest(RequestType.Problem));
            }

            if ((!String.IsNullOrEmpty(sourceIDs) && !RegexVerify.IsNumericIDs(sourceIDs)) || (!String.IsNullOrEmpty(targetIDs) && !RegexVerify.IsNumericIDs(targetIDs)))
            {
                return(MethodResult.InvalidRequest(RequestType.ProblemCategory));
            }

            StringBuilder deleteIDs = new StringBuilder();
            StringBuilder insertIDs = new StringBuilder();
            List <String> sourceid  = (String.IsNullOrEmpty(sourceIDs) ? new List <String>() : new List <String>(sourceIDs.Split(',')));
            List <String> targetid  = (String.IsNullOrEmpty(targetIDs) ? new List <String>() : new List <String>(targetIDs.Split(',')));

            for (Int32 i = 0; i < targetid.Count; i++)//删除sourceIDs和targetIDs中相同的数据
            {
                for (Int32 j = 0; j < sourceid.Count; j++)
                {
                    if (String.Equals(targetid[i], sourceid[j], StringComparison.OrdinalIgnoreCase))
                    {
                        targetid.RemoveAt(i);
                        sourceid.RemoveAt(j);
                        i--;
                        j--;
                        break;
                    }
                }
            }

            for (Int32 i = 0; i < sourceid.Count; i++)//设置deleteIDs
            {
                if (i > 0)
                {
                    deleteIDs.Append(',');
                }
                deleteIDs.Append(sourceid[i]);
            }

            for (Int32 i = 0; i < targetid.Count; i++)//设置insertIDs
            {
                if (i > 0)
                {
                    insertIDs.Append(',');
                }
                insertIDs.Append(targetid[i]);
            }

            Boolean ret = true;

            if (deleteIDs.Length > 0)
            {
                ret &= (ProblemCategoryItemRepository.Instance.DeleteEntities(problemID, deleteIDs.ToString()) > 0);
            }
            if (insertIDs.Length > 0)
            {
                ret &= (ProblemCategoryItemRepository.Instance.InsertEntity(problemID, insertIDs.ToString()) > 0);
            }

            if (!ret)
            {
                return(MethodResult.FailedAndLog("No problem's category was updated!"));
            }

            return(MethodResult.SuccessAndLog("Admin update problem's category, id = {0}, new category = {1}", problemID.ToString(), targetIDs));
        }