public ICommandResult Handle(UpdateNurseCommand command) { command.Validate(); if (command.Invalid) { AddNotifications(command); return(new CommandResult(false, command.Notifications.Messages(), command)); } Nurse nurse = new Nurse(command.FullName, command.CpfNumber, command.Coren, command.BirthDate.Value, command.DocumentType) { Id = command.Id }; nurse.SetHospitalId(command.HospitalId); AddNotifications(nurse); if (Invalid) { return(new CommandResult(false, nurse.Notifications.Messages(), command)); } _nurseRepository.Update(nurse); _uow.Commit(); return(new CommandResult(true, "Sucesso!", nurse)); }
public async Task <ICommandExit> Put(Guid id, [FromBody] UpdateNurseCommand updateNurseCommand) { updateNurseCommand.Id = id; var response = await _commandHandlerNurse.Handler(updateNurseCommand); return(response); }
public async Task <ICommandExit> Handler(UpdateNurseCommand command) { Nurse nurse = await _nurseRepository.GetById(command.Id); nurse.UpdateNurse(command.Name, command.CPF, command.BirthDate, command.Coren, command.Id_Hospital); if (Invalid) { return(new CommandExit(false, "Erro ao cadastrar Nurse", nurse)); } await Task.Factory.StartNew(() => { _nurseRepository.Update(nurse); }); return(new CommandExit(true, "Atualização Realizado Com Sucesso", nurse)); }
public async Task <ICommandResult> Handler(UpdateNurseCommand command) { command.Validate(); if (!command.Valid) { return(new GenericCommandResult(false, "Ops, parece que algo está errado!", command.Notifications)); } var nurse = await _nurseRepository.GetById(command.Id); nurse.updateNurse(command.Name, command.CPF, command.Coren, command.DateBirth); if (nurse.Invalid) { return(new GenericCommandResult(false, "ocoreu algum erro", command.Notifications)); } await _nurseRepository.Update(nurse); return(new GenericCommandResult(true, "Dados do Enfermeiro atualizado", nurse)); }
public async Task <IActionResult> Update([FromBody] UpdateNurseCommand command, [FromServices] NurseHandler handler) { return(Ok(await handler.Handler(command))); }
public ICommandResult Put([FromBody] UpdateNurseCommand value) { var result = _handler.Handle(value); return(result); }