Esempio n. 1
0
        public ActionResult UpdateAnimal(int id, [FromBody] UpdateAnimalDTO updatedAnimal)
        {
            if (!ModelState.IsValid || null == updatedAnimal)
            {
                return(NoContent());
            }


            try
            {
                Animal selectedAnimal = _context.Animals.Where(a => a.Id == id)
                                        .Single();
                selectedAnimal.Name      = updatedAnimal.Name;
                selectedAnimal.Age       = updatedAnimal.Age;
                selectedAnimal.Reference = updatedAnimal.Reference;
                selectedAnimal.Photo     = selectedAnimal.Photo;
                selectedAnimal.Status    = _context.Status.Where(s => s.Description == updatedAnimal.Status)
                                           .Single();
                selectedAnimal.Volunteer = _context.Volunteers.Where(v => v.Id == updatedAnimal.VolunteerDTO.Id)
                                           .Single();

                _context.Update(selectedAnimal);
                _context.SaveChanges();
                return(Ok());
            }
            catch
            {
                return(NotFound());
            }
        }
Esempio n. 2
0
        public async Task <BasicAnimalDTO> UpdateTotemAsync(UpdateAnimalDTO viewModel, int id)
        {
            var totem = await _totemRepository.FindByIdAsync(id);


            if (totem == null)
            {
                throw new EntityNotFoundException($"Totem met id {id} werd niet gevonden");
            }

            totem.Naam = viewModel.Naam.Trim();
            await _totemRepository.SaveChangesAsync();

            return(_mapper.Map <BasicAnimalDTO>(totem));
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateTotem([FromBody] UpdateAnimalDTO viewModel, [FromRoute] int id)
        {
            var updatedTotem = await _totemService.UpdateTotemAsync(viewModel, id);

            return(Ok(updatedTotem));
        }