コード例 #1
0
        public async Task <IActionResult> SelfDeleteCharacter(
            [FromRoute] Guid characterId,
            [FromServices] Domain.Users.IUserRepository userRepository,
            CancellationToken cancellationToken)
        {
            var user = await userRepository.Get(HttpContext.GetUserId(), HttpContext.GetGuildId(), cancellationToken);

            try{
                user.CharacterRemove(characterId);
            }
            catch (CharacterNotFound e) {
                throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.CharacterNotFound, e.Message);
            }

            userRepository.Save(user);
            return(Ok(new { }));
        }
コード例 #2
0
        public async Task <IActionResult> SelfAddCharacter(
            [FromBody] AddCharacterBinding binding,
            [FromServices] Domain.Users.IUserRepository userRepository,
            CancellationToken cancellationToken)
        {
            var user = await userRepository.Get(HttpContext.GetUserId(), HttpContext.GetGuildId(), cancellationToken);

            try{
                user.AddCharacter(binding.Id, binding.Name, binding.ClassName, binding.IsMain);
            }
            catch (CharacterAlreadyExists e) {
                throw new ApiException(HttpStatusCode.Conflict, ErrorCodes.CharacterAlreadyExists, e.Message, e.Character.ToDictionary(), e);
            }

            userRepository.Save(user);
            return(Ok(new { }));
        }
コード例 #3
0
        public async Task <IActionResult> ChangeStatus(
            [FromRoute] Guid userId,
            [FromBody] ChangeStatusBinding binding,
            [FromServices] Domain.Users.IUserRepository userRepository,
            CancellationToken cancellationToken)
        {
            var user = await userRepository.Get(userId, HttpContext.GetGuildId(), cancellationToken);

            if (user == null)
            {
                throw new ApiException(HttpStatusCode.NotFound, ErrorCodes.GamerNotFound, "Gamer not found");
            }

            user.ChangeStatus(binding.Status);

            userRepository.Save(user);
            return(Ok(new { }));
        }