コード例 #1
0
        public async Task <ActionResult <GameAction> > PostGameAction([FromBody] DiceRequest diceRequest)
        {
            Dice rolledDice = _diceService.GenerateDiceAction(diceRequest.Dice);

            var currentCharacter = _context
                                   .Characters
                                   .Include(character => character.Characteristics)
                                   .First(character => character.Id == diceRequest.CharacterId);

            var characteristic = currentCharacter.Characteristics[diceRequest.Characteristic];

            var diceAction = new DiceAction()
            {
                Bonuses             = "",
                CharacterId         = diceRequest.CharacterId,
                Result              = rolledDice.Result,
                RolledDice          = rolledDice.Max,
                CharacteristicValue = characteristic,
                Characteristic      = diceRequest.Characteristic,
                RoomId              = diceRequest.RoomId
            };

            _context.Actions.Add(diceAction);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGameAction", new { id = diceAction.Id }, diceAction));
        }