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 { })); }
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 { })); }
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 { })); }