public IActionResult Update(int id, [FromBody] UpdateFamousPersonCommand command) { _log.LogInformation( "Updating person with id {PersonId}", id); _famousPersonService.UpdatePerson(id, command); return(Ok()); }
public void UpdateFamousPerson(UpdateFamousPersonCommand cmd) { var person = _context.Persons.Find(cmd.Id); if (person == null) { throw new Exception("Unable to find that person"); } if (person.IsDeleted) { throw new Exception("Unable to update a deleted person"); } cmd.UpdatePerson(person); _context.SaveChanges(); }
public void UpdatePerson(int id, UpdateFamousPersonCommand command) { var person = _context.Persons.Find(id); if (person == null) { throw new Exception("Unable to find person"); } person.FirstName = command.FirstName; person.LastName = command.LastName; person.BirthDate = command.BirthDate; person.City = command.City; person.State = command.State; _context.SaveChanges(); }
public IActionResult Edit(UpdateFamousPersonCommand command) { try { if (ModelState.IsValid) { _service.UpdateFamousPerson(command); return(RedirectToAction(nameof(View), new { id = command.Id })); } } catch (Exception) { ModelState.AddModelError( string.Empty, "An error occured saving the recipe" ); } return(View(command)); }