示例#1
0
        public ActionResult RemoveCharacter(AuthUserCharacter model)
        {
            string username = User.Identity.GetUserId();

            // Check if the character has uploaded any logs or created any sessions. If so, we need to set them to 'removed', not remove them.

            // If there are pending guild applications, remove them
            var pendingGuildApplication = _authUserCharacterGuildApplicationRepository.GetPendingApplicationForCharacter(model.Id);

            if (pendingGuildApplication != null)
            {
                _authUserCharacterGuildApplicationRepository.Remove(pendingGuildApplication.Id, username);
            }

            // Now, remove the user
            var result = _authUserCharRepository.Delete(username, model.Id);

            if (result.Success)
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", result.Message);

            return(View(model));
        }
示例#2
0
        public ActionResult CreateCharacter()
        {
            var character = new AuthUserCharacter()
            {
                Shards = _shardRepository.GetAll().ToList()
            };

            return(View(character));
        }
示例#3
0
        public ActionResult KickMember(AuthUserCharacter model)
        {
            var result = _authUserCharacterRepository.KickCharacterFromGuild(model.Id, model.GuildId,
                                                                             User.Identity.GetUserId());

            if (!result.Success)
            {
                ModelState.AddModelError("", result.Message);
                return(View(model));
            }
            return(RedirectToAction("Index", new { @id = model.GuildId }));
        }
示例#4
0
        public ActionResult CreateCharacter(AuthUserCharacter model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = _authUserCharRepository.Create(User.Identity.GetUserId(), model);

            if (result.Success)
            {
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", result.Message);

            model.Shards = _shardRepository.GetAll().ToList();
            return(View(model));
        }
示例#5
0
        // Command methods

        /// <summary>
        /// Create a new character and link it to the user performing the create.
        /// Validation of existing characters is performed here, prior to the insert. Updated for MySQL
        /// </summary>
        /// <param name="email">The email address of the user performing the create</param>
        /// <param name="character">The character to add</param>
        /// <returns>A ReturnValue indicating success or failure, along with optional messages</returns>
        public ReturnValue Create(string email, AuthUserCharacter character)
        {
            var returnValue = new ReturnValue();

            // Check to see if this character name has been taken on the given shard already. Ignore users that are 'removed'
            string timeElapsed;
            var    alreadyExists = Query(
                q =>
                q.Query <long>(MySQL.AuthUserCharacter.CharacterExistsOnShard,
                               new { @characterName = character.CharacterName, @shardId = character.ShardId }), out timeElapsed)
                                   .SingleOrDefault() == 1;

            if (alreadyExists)
            {
                returnValue.Message = string.Format("The character '{0}' already exists!", character.CharacterName);
                return(returnValue);
            }

            // Check to see if this user has 6 characters on this shard already
            var totalCharacters = Query(
                q =>
                q.Query <long>(MySQL.AuthUserCharacter.CheckMaxCharacterCountForAccount,
                               new { email, @shardId = character.ShardId }), out timeElapsed).SingleOrDefault();

            if (totalCharacters > 5)
            {
                returnValue.Message = "You have already created the maximum number of characters on this shard.";
                return(returnValue);
            }

            // Get the AuthUserId for this user

            var userId = GetAuthUserIdByEmail(email);

            if (userId == 0)
            {
                returnValue.Message = string.Format("No user was found with the email address {0}", email);
                return(returnValue);
            }

            // Add the character
            try
            {
                DapperDb dapperDb = DapperDb.Init(OpenConnection(), 3, false);

                var newId = dapperDb.AuthUserCharacterTable.Insert(
                    new //AuthUserCharacter()
                {
                    AuthUserId    = userId,
                    CharacterName = character.CharacterName,
                    ShardId       = character.ShardId
                });

                if (newId > 0)
                {
                    returnValue.Success = true;
                }
            }
            catch (Exception ex)
            {
                returnValue.Message = ex.Message;
            }

            return(returnValue);
        }