Exemple #1
0
        public ActionResult <SafariVacation> Delete(int animalId)
        {
            var db     = new SafariHWContext();
            var animal = db.SafariVacation.FirstOrDefault(f => f.Id == animalId);

            db.SafariVacation.Remove(animal);
            db.SaveChanges();

            return(animal);
        }
Exemple #2
0
        public ActionResult <SafariVacation> Post([FromBody] SafariVacation seenAnimals)

        {
            var db = new SafariHWContext();

            db.SafariVacation.Add(seenAnimals);
            db.SaveChanges();

            return(seenAnimals);
        }
Exemple #3
0
        public ActionResult <SafariVacation> Put([FromRoute] int id, [FromBody] SafariVacation updatedData)
        {
            var db     = new SafariHWContext();
            var animal = db.SafariVacation.FirstOrDefault(f => f.Id == id);

            if (animal != null)
            {
                // update the values
                animal.CountOfTimesSeen   = updatedData.CountOfTimesSeen;
                animal.Species            = updatedData.Species;
                animal.LocationOfLastSeen = updatedData.LocationOfLastSeen;
                db.SaveChanges();
                return(animal);
            }
            else
            {
                return(NotFound(new { id, updatedData }));
            }
        }