public async Task <ActionResult> Post([FromBody] AutorCreateDto autorCreate)
        {
            var autor = mapper.Map <Autor>(autorCreate);

            context.Add(autor);

            await context.SaveChangesAsync();

            var autorDto = mapper.Map <AutorDto>(autor);

            return(new CreatedAtRouteResult("ObtenerAutor", new { id = autor.Id }, autorDto));
        }
        public async Task <ActionResult <Autor> > Put(int id, [FromBody] AutorCreateDto autorActualizaion)
        {
            var autorDb = await context.Autores.FindAsync(id);

            if (autorDb == null)
            {
                return(NotFound());
            }
            mapper.Map(autorActualizaion, autorDb);
            await context.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #3
0
        public async Task <ActionResult <AutorDTO> > PostWithImage([FromForm] AutorCreateDto autorCreateDto)
        {
            var autor = _mapper.Map <Autor>(autorCreateDto);

            if (TryValidateModel(autor))
            {
                _repository.Autor.Add(autor);
                await _repository.SaveAsync();

                var autorCreatedDto = _mapper.Map <AutorDTO>(autor);
                return(CreatedAtAction(nameof(Get), new { id = autorCreatedDto.AutorId }, autorCreatedDto));
            }

            return(BadRequest(ModelState));
        }