public ActionResult <SeenAnimals> Post([FromBody] SeenAnimals seenAnimals) { var db = new SeenAnimalsContext(); db.SeenAnimals.Add(seenAnimals); db.SaveChanges(); return(seenAnimals); }
public ActionResult <SeenAnimals> Put([FromRoute] int id, [FromBody] SeenAnimals updatedData) { var db = new SeenAnimalsContext(); var seenAnimals = db.SeenAnimals.FirstOrDefault(animals => animals.Id == id); seenAnimals.Species = updatedData.Species; seenAnimals.CountOfTimesSeen = updatedData.CountOfTimesSeen; seenAnimals.LocationOfLastSeen = updatedData.LocationOfLastSeen; db.SaveChanges(); return(updatedData); }
public ActionResult Delete(int id) { var db = new SeenAnimalsContext(); var animal = db.SeenAnimals.FirstOrDefault(a => a.Id == id); if (animal == null) { return(NotFound()); } db.SeenAnimals.Remove(animal); db.SaveChanges(); return(Ok()); }