public async Task <BaseResponse <Disease> > Handle(UpdateDiseaseCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Disease> () { ReponseName = nameof(UpdateDiseaseCommand), Content = new List <Disease> () { } }; var entity = await _diseaseRepository.GetOneAsync(p => p.Id == request.Id); if (entity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(Disease)} not found."; response.Content = null; } else { _mapper.Map(request, entity, typeof(UpdateDiseaseCommand), typeof(Disease)); await _diseaseRepository.UpdateAsync(entity); response.Status = ResponseType.Success; response.Message = $"{nameof(Disease)} updated successfully."; response.Content.Add(entity); } return(response); }
public async Task <ActionResult <BaseResponse <Disease> > > UpdateDisease(UpdateDiseaseCommand command) { try { var result = await _mediator.Send(command); return(Ok(result)); } catch (ValidationException ex) { var err = new BaseResponse <Disease> (); err.Status = ResponseType.Error; err.Message = ex.Message; err.Content = null; return(Ok(err)); } }
public ActionResult Edit(FormCollection collection) { try { var data = new UpdateDiseaseCommand(Guid.Parse(collection["Id"]), collection["Name"], collection["Cid"], collection["Description"]); _serviceDisease.Update(data); return(RedirectToAction("Index")); } catch (Exception msg) { var mensagemError = msg.Message; return(View()); } }
public Disease Update(UpdateDiseaseCommand command) { // Cria a instâcia do usuário var domain = new Disease(command.Id, command.Name, command.CID, command.Description); // Tenta ações e regras de negócio no domínio //domain.Register(); // Salva as alterações da tabela no contexto do banco de dados _repository.Update(domain); // Chama o commit if (Commit()) { // Dispara o evento de usuário registrado DomainEvent.Raise(new OnDiseaseRegisteredEvent(domain)); // Retorna o usuário return(domain); } // Se não comitou, retorna nulo return(null); }