Ejemplo n.º 1
0
        public async Task <IActionResult> PutAnimal(int id, Animal animal)
        {
            if (id != animal.AnimalId)
            {
                return(BadRequest());
            }

            _context.Entry(animal).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnimalExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Animal> > PostAnimal(Animal animal)
        {
            _context.Animals.Add(animal);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("PostAnimal", new { id = animal.Id }, animal));
        }
        public async Task <IActionResult> Create([Bind("AnimalId,Name,NumberOfLegs,Weight,IsItCute,Length")] Animal animal)
        {
            if (ModelState.IsValid)
            {
                animal.AnimalId = Guid.NewGuid();
                _context.Add(animal);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(animal));
        }