public async Task <IActionResult> Adopted(int id) { var animal = await _AnimalService.FindByIdAsync(id); var user = await UserManager.GetUserAsync(HttpContext.User); if (animal.UsuarioId == user.Id) { animal.Adotado = true; _TccContext.Update(animal); _TccContext.SaveChanges(); animal.Usuario = await UserManager.FindByIdAsync(animal.UsuarioId); animal.Usuario.Cidade = await _CidadeService.FindByIdAsync(animal.Usuario.CidadeId); return(View("Details", animal)); } else { return(View("AccessDenied")); } }
public async Task UpdateAsync(Usuario obj) { bool hasAny = await _Context.Usuario.AnyAsync(x => x.Id == obj.Id); if (!hasAny) { throw new NotFoundException("Id not Found"); } try { _Context.Update(obj); await _Context.SaveChangesAsync(); } catch (DbConcurrencyException e) { throw new DbConcurrencyException(e.Message); } }