Exemplo n.º 1
0
        public ActionResult <SeenAnimals> Post([FromBody] SeenAnimals seenAnimals)
        {
            var db = new SeenAnimalsContext();

            db.SeenAnimals.Add(seenAnimals);
            db.SaveChanges();
            return(seenAnimals);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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());
        }