Ejemplo n.º 1
0
 public IActionResult Update(int id, [FromBody] UpdateFamousPersonCommand command)
 {
     _log.LogInformation(
         "Updating person with id {PersonId}", id);
     _famousPersonService.UpdatePerson(id, command);
     return(Ok());
 }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 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));
 }