Пример #1
0
        public async Task <IActionResult> ActiveToggle(int id)
        {
            var userId      = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var petFromRepo = await _repo.GetPet(id);

            if (petFromRepo.UserId != userId)
            {
                return(Unauthorized());
            }

            _repo.ActiveToggle(petFromRepo);


            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Deactivating pet {id} failed on save");
        }