public async Task <IActionResult> Edit(AnimalDetailsViewModel model) { if (ModelState.IsValid) { var animal = await _animalRepository.GetAnimalWithUserAsync(model.Id); if (animal == null) { return(NotFound()); } if ((this.User.Identity.Name != animal.User.UserName) && !this.User.IsInRole("Admin")) { return(NotFound()); } model.ImageUrl = animal.ImageUrl; animal = _converterHelper.AnimalDetailsToAnimal(animal, model); await _animalRepository.UpdateAsync(animal); } model.User = await _userHelper.GetUserByEmailAsync(model.User.UserName); model.Appointments = _appointmentRepository.GetAnimalAppointments(model.Id); return(View("Details", model)); }