コード例 #1
0
        public ActionResult <APIAnimals> AddAnimal([FromBody] APIAnimals AddedAnimal)
        {
            var db = new APIAnimalsContext();

            db.APIAnimals.Add(AddedAnimal);
            db.SaveChanges();
            return(AddedAnimal);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
            }
        }