コード例 #1
0
        public async Task <ApiResponse <object> > Create(CreateWeaponDto request)
        {
            var command = new CreateWeaponCommand
            {
                Name   = request.Name,
                Damage = request.Damage
            };
            await _operationMediator.HandleAsync(command);

            var location = Url.Link(GetByIdRouteName, new { id = command.GeneratedId });

            return(ApiResponse.Created(location, command.GeneratedId));
        }
コード例 #2
0
        public async Task <Weapon> Handle(CreateWeaponCommand command)
        {
            var weapon = new Weapon(
                command.Name,
                command.Strength,
                command.Magic,
                command.RangeType
                );

            if (weapon.Invalid)
            {
                notificationContext.AddNotifications(weapon.ValidationResult);
                return(null);
            }

            this.mongoRepository.Add(weapon);

            await this.repository.AddAsync(weapon);

            return(weapon);
        }
コード例 #3
0
        public async Task <IActionResult> PostWeapon(CreateWeaponCommand createWeaponCommand)
        {
            var response = await this.createWeaponHandler.Handle(createWeaponCommand);

            return(Ok(response));
        }