예제 #1
0
        public async Task <IActionResult> Put(Guid id, [FromBody] LivroDto dto)
        {
            var validation = _validator.Validate(dto);

            if (!validation.IsValid)
            {
                throw new ArgumentException(string.Join(", ", validation.Errors));
            }

            var entity = dto.ToEntity();

            entity.Id = id;

            var updated = await _livroRepository.Update(entity);

            return(Ok(updated));
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] LivroDto dto)
        {
            var validation = _validator.Validate(dto);

            if (!validation.IsValid)
            {
                throw new ArgumentException(string.Join(", ", validation.Errors));
            }

            var entity = dto.ToEntity();

            entity.Id = Guid.NewGuid();

            var createad = await _livroRepository.Add(entity);

            return(Ok(createad));
        }