public async Task <ActionResult <Categoria> > CreateCategoria([FromBody] Categoria categoria)
        {
            _log.LogDebug($"REST request to save Categoria : {categoria}");
            if (categoria.Id != 0)
            {
                throw new BadRequestAlertException("A new categoria cannot already have an ID", EntityName, "idexists");
            }

            await _categoriaRepository.CreateOrUpdateAsync(categoria);

            await _categoriaRepository.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCategoria), new { id = categoria.Id }, categoria)
                   .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, categoria.Id.ToString())));
        }
Exemplo n.º 2
0
        public async Task GetAllCategorias()
        {
            // Initialize the database
            await _categoriaRepository.CreateOrUpdateAsync(_categoria);

            await _categoriaRepository.SaveChangesAsync();

            // Get all the categoriaList
            var response = await _client.GetAsync("/api/categorias?sort=id,desc");

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var json = JToken.Parse(await response.Content.ReadAsStringAsync());

            json.SelectTokens("$.[*].id").Should().Contain(_categoria.Id);
            json.SelectTokens("$.[*].nome").Should().Contain(DefaultNome);
        }