Example #1
0
        public async Task <BasicAnimalDTO> AddTotemAsync(AddAnimalDTO viewModel)
        {
            var exists = await _totemRepository.FindByNaamAsync(viewModel.Naam) != null;

            if (exists)
            {
                throw new EntityExistsException($"Totem met naam {viewModel.Naam} bestaat al");
            }

            //Trailing spaces verwijderen uit nieuwe totem
            viewModel.Naam = viewModel.Naam.Trim();

            var newTotem = _mapper.Map <Totem>(viewModel);

            await _totemRepository.AddAsync(newTotem);

            await _totemRepository.SaveChangesAsync();

            var model = _mapper.Map <BasicAnimalDTO>(newTotem);

            return(model);
        }
Example #2
0
        public async Task <IActionResult> AddTotem([FromBody] AddAnimalDTO viewModel)
        {
            var newTotem = await _totemService.AddTotemAsync(viewModel);

            return(CreatedAtRoute("GetTotemById", new { id = newTotem.Id }, newTotem));
        }