public ActionResult Post([FromBody] HerdCategory category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _repository.Save(category); return(Ok(category)); } catch { return(BadRequest(new { message = "Não foi possível salvar a categoria." })); } }
public ActionResult Put(int id, [FromBody] HerdCategory category) { if (id != category.Id) { return(NotFound(new { message = "Categoria não encontrada." })); } try { _repository.Update(category); return(Ok(category)); } catch (DbUpdateConcurrencyException) { return(BadRequest(new { message = "Esta categoria já foi atualizada." })); } catch { return(BadRequest(new { message = "Não foi possível atualizar a categoria." })); } }
public void Update(HerdCategory category) { _context.Entry <HerdCategory>(category).State = EntityState.Modified; _context.SaveChanges(); }
public void Save(HerdCategory category) { _context.HerdCategories.Add(category); _context.SaveChanges(); }