Example #1
0
        /// <summary>
        /// 判断指定竞赛是否包含指定用户
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="userName">用户名</param>
        /// <returns>是否包含指定用户</returns>
        public static Boolean ContestContainsUser(Int32 cid, String userName)
        {
            Dictionary <String, ContestUserEntity> dict = GetContestUserList(cid);

            if (dict == null)
            {
                return(false);
            }

            ContestUserEntity entity = null;

            if (!dict.TryGetValue(userName, out entity))
            {
                return(false);
            }

            return(entity.IsEnable);
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// 添加指定ID的竞赛用户
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="usernames">竞赛用户</param>
        /// <returns>是否成功添加</returns>
        public static IMethodResult AdminInsertContestUsers(Int32 cid, String usernames)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(usernames))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            Dictionary <String, ContestUserEntity> dict = new Dictionary <String, ContestUserEntity>();
            StringBuilder names = new StringBuilder();

            String[] namelist = usernames.Split('\n');

            for (Int32 i = 0; i < namelist.Length; i++)
            {
                String[] name = namelist[i].Replace('\t', ' ').Split(' ');

                if (name.Length < 1 || String.IsNullOrEmpty(name[0].Trim()))
                {
                    continue;
                }

                ContestUserEntity entity = new ContestUserEntity()
                {
                    ContestID    = cid,
                    UserName     = name[0].Replace("\r", "").Trim(),
                    RealName     = (name.Length >= 2 ? name[1].Replace("\r", "").Trim() : ""),
                    IsEnable     = true,
                    RegisterTime = DateTime.Now
                };

                if (!dict.ContainsKey(entity.UserName))
                {
                    names.Append(names.Length > 0 ? "," : "").Append(entity.UserName);
                }

                dict[entity.UserName] = entity;
            }

            try
            {
                Int32 count = ContestUserRepository.Instance.InsertEntities(cid, names.ToString(), dict);

                if (count <= 0)
                {
                    return(MethodResult.FailedAndLog("No contest user was added!"));
                }

                ContestUserCache.RemoveContestUserListCache(cid);

                return(MethodResult.SuccessAndLog <Int32>(count, "Admin add contest user, cid = {0}, username = {1}", cid.ToString(), usernames));
            }
            catch (DbException)
            {
                return(MethodResult.FailedAndLog("Failed to add these users, please check whether the names are all correct."));
            }
        }