public IActionResult Create(Animals model) { if (ModelState.IsValid) { var maxId = catRepository.GetCats().Max(x => x.Id) + 1; model.Id = maxId; catRepository.AddCat(model); return(RedirectToAction("List")); } return(View(model)); }
public bool AddCat(string cat) { Cat deserialize = JsonConvert.DeserializeObject <Cat>(cat); if (catsContext.CatExists(deserialize.Name)) { return(false); } catsContext.AddCat(cat); return(true); }
public ActionResult <Cat> Post([FromBody] Cat value) { return(Created("/api/cats/", _catRepo.AddCat(value))); }