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

            db.SeenAnimals.Add(seenAnimals);
            db.SaveChanges();
            return(seenAnimals);
        }
Esempio 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);
        }
Esempio 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());
        }
Esempio n. 4
0
        public IEnumerable <SeenAnimals> GetbyLocation(string location)
        {
            var db = new SeenAnimalsContext();

            return(db.SeenAnimals.Where(w => w.LocationOfLastSeen.ToLower() == location.ToLower()));
        }
Esempio n. 5
0
        // https://localhost:5001/api/SeenAnimals
        public IEnumerable <SeenAnimals> Get()
        {
            var db = new SeenAnimalsContext();

            return(db.SeenAnimals.OrderBy(o => o.CountOfTimesSeen));
        }