Ejemplo n.º 1
0
        public async Task <ActionResult <Character> > CreateCharacter(Character character)
        {
            _logger.LogInformation("POST /api/characters");

            try
            {
                character = await _charactersService.CreateCharacter(character);
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }

            return(CreatedAtAction(nameof(GetCharacter), new { id = character.Id }, character));
        }
Ejemplo n.º 2
0
 public void Post([FromBody] SwCharacter newCharacter)
 {
     _charactersService.CreateCharacter(newCharacter);
 }
Ejemplo n.º 3
0
        public DnDBeyondMutation(ICharactersService charactersService, IHitPointsService hitPointsService)
        {
            Name = "Mutation";

            // Create new character
            Field <CharacterType>(
                "createCharacter",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <Inputs.CharacterInput> > {
                Name = "character"
            }),
                resolve: context =>
            {
                var character = context.GetArgument <Character>("character");
                return(charactersService.CreateCharacter(character));
            });

            // Update character's temporary hit points
            Field <CharacterType>(
                "updateTemporaryHitPoints",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <IntGraphType> {
                Name = "temporaryHitPoints"
            }),
                resolve: context =>
            {
                var id = context.GetArgument <long>("id");
                var temporaryHitPoints = context.GetArgument <int>("temporaryHitPoints");
                return(hitPointsService.UpdateTemporaryHitPoints(id, temporaryHitPoints));
            });

            // Damage a character
            Field <CharacterType>(
                "damageCharacter",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <IntGraphType> {
                Name = "damage"
            },
                    new QueryArgument <StringGraphType> {
                Name = "damageType"
            }),
                resolve: context =>
            {
                var id         = context.GetArgument <long>("id");
                var damage     = context.GetArgument <int>("damage");
                var damageType = context.GetArgument <string>("damageType");
                return(hitPointsService.DamageCharacter(id, damage, damageType));
            });

            // Heal a character
            Field <CharacterType>(
                "healCharacter",
                arguments: new QueryArguments(
                    new QueryArgument <IdGraphType> {
                Name = "id"
            },
                    new QueryArgument <IntGraphType> {
                Name = "heal"
            }),
                resolve: context =>
            {
                var id   = context.GetArgument <long>("id");
                var heal = context.GetArgument <int>("heal");
                return(hitPointsService.HealCharacter(id, heal));
            });
        }