public ActionResult <APIAnimals> AddAnimal([FromBody] APIAnimals AddedAnimal) { var db = new APIAnimalsContext(); db.APIAnimals.Add(AddedAnimal); db.SaveChanges(); return(AddedAnimal); }
public ActionResult <APIAnimals> DeleteAction([FromRoute] int id) { var db = new APIAnimalsContext(); var AnimalToDelete = db.APIAnimals.FirstOrDefault(animals => animals.ID == id); db.APIAnimals.Remove(AnimalToDelete); db.SaveChanges(); return(AnimalToDelete); }
public ActionResult <APIAnimals> AddSighting([FromRoute] string animal) { var db = new APIAnimalsContext(); var SelectedAnimal = db.APIAnimals.FirstOrDefault(animals => animals.Species == animal.ToString()); if (SelectedAnimal == null) { return(NotFound()); } else { SelectedAnimal.CountOfTimesSeen++; db.SaveChanges(); return(SelectedAnimal); } }