public async Task <Unit> Handle(CreateCharacterCommand request, CancellationToken cancellationToken)
        {
            Character character = _mapper.Map <Character>(request.CreateCharacter);
            await _characterRepository.CreateAsync(character);

            return(Unit.Value);
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] CharacterCreateDTO character)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = await _repository.CreateAsync(character);

            return(CreatedAtAction(nameof(Get), new { id }, null));
        }
        public async Task <CharacterModel> CreateAsync(CharacterModel model)
        {
            var result = await _characterRepository.CreateAsync(new CharacterEntity(model), true);

            if (result == null)
            {
                return(null);
            }

            return(new CharacterModel(result));
        }
Esempio n. 4
0
        public async Task <ActionResult <CharacterDTO> > Post([FromBody] CharacterCreateUpdateDTO character)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            var dto = await _repository.CreateAsync(character);

            return(CreatedAtAction(nameof(Get), new { id = dto.Id }, dto));
        }
Esempio n. 5
0
        private async Task Seed()
        {
            var characters = new[]
            {
                new CharacterCreateDTO {
                    Name = "Philip J. Fry", Planet = "Earth", Species = "Human", Image = "ms-appx:///Assets/images/philip-fry.png"
                },
                new CharacterCreateDTO {
                    Name = "Turanga Leela", Planet = "Earth", Species = "Mutant-Human", Image = "ms-appx:///Assets/images/turanga-leela.png"
                },
                new CharacterCreateDTO {
                    Name = "Bender Bending Rodríguez", Planet = "Earth", Species = "Robot", Image = "ms-appx:///Assets/images/bender.png"
                },
                new CharacterCreateDTO {
                    Name = "Hubert J. Farnsworth", Planet = "Earth", Species = "Human", Image = "ms-appx:///Assets/images/hubert-farnsworth.png"
                },
                new CharacterCreateDTO {
                    Name = "John A. Zoidberg", Planet = "Decapod 10", Species = "Decapodian", Image = "ms-appx:///Assets/images/zoidberg.png"
                },
                new CharacterCreateDTO {
                    Name = "Amy Wong", Planet = "Mars", Species = "Human", Image = "ms-appx:///Assets/images/amy-wong.png"
                },
                new CharacterCreateDTO {
                    Name = "Hermes Conrad", Planet = "Earth", Species = "Human", Image = "ms-appx:///Assets/images/hermes-conrad.png"
                },
                new CharacterCreateDTO {
                    Name = "Scruffy", Planet = "Earth", Species = "Human", Image = null
                }
            };

            foreach (var character in characters)
            {
                await _repository.CreateAsync(character);
            }

            Initialize();
        }
        public async Task <ServicesResult> CreateAsync(DragonBallPostRequest request)
        {
            var entity = await _characterRepository.CreateAsync(new CharacterEntity(request), true);

            return(Created(entity));
        }
Esempio n. 7
0
        public async Task <ActionResult <CharacterDTO> > Post([FromBody] CharacterCreateUpdateDTO character)
        {
            var dto = await _repository.CreateAsync(character);

            return(CreatedAtAction(nameof(Get), new { id = dto.Id }, dto));
        }