Exemplo n.º 1
0
        public async Task <IActionResult> Update(
            Guid id, [FromBody] CategoryUpdateApi categoryUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!await CategoryExists(id))
            {
                return(NotFound());
            }

            await _categoryRepository.Update(new Category()
            {
                Id = id, Name = categoryUpdate.Name, Note = categoryUpdate.Note
            });

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] CategoryUpdateApi categoryUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var category = new Category
            {
                Id   = Guid.NewGuid(),
                Name = categoryUpdate.Name,
                Note = categoryUpdate.Note
            };
            await _categoryRepository.Add(category);

            return(CreatedAtRoute("GetCategory",
                                  new { Controller = "Category", id = category.Id },
                                  new CategoryApi {
                Id = category.Id, Name = category.Name, Note = category.Note
            }));
        }