public Task <bool> Handle(UpdateEmpresaCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } var empresa = new Empresa(message.Id, message.NomeFantasia, message.CNPJ, message.UF); var empresaExistente = _empresaRepository.GetByEmail(empresa.CNPJ); if (empresaExistente != null && empresaExistente.Id != empresa.Id) { if (!empresaExistente.Equals(empresa)) { Bus.RaiseEvent(new DomainNotification(message.MessageType, "O CNPJ já foi salvo anteriormente.")); return(Task.FromResult(false)); } } _empresaRepository.Update(empresa); if (Commit()) { Bus.RaiseEvent(new EmpresaUpdatedEvent(empresa.Id, empresa.NomeFantasia, empresa.CNPJ, empresa.UF)); } return(Task.FromResult(true)); }
public Task <long> UpdateEmpresa(UpdateEmpresaCommand command) { var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture, $"{ResourceEmpresa}/UpdateEmpresa")); return(Post(requestUrl, command)); }
public async Task <ActionResult <bool> > UpdateEmpresa(UpdateEmpresaCommand command) { try { var result = await Mediator.Send(command); return(result); } catch (Exception e) { Console.WriteLine(e); throw; } }
public ActionResult Edit(int id, IFormCollection collection) { try { var command = new UpdateEmpresaCommand { Id = id, NomRazaoSocial = collection["empresa"].ToString(), AlteradoPor = User.Identity.Name, NumCnpj = collection["cnpj"].ToString(), NumTelefone = collection["telefone"].ToString() }; ApiClientFactory.Instance.UpdateEmpresa(command); return(RedirectToAction(nameof(Index), new { crud = (int)EnumCrud.Updated })); } catch { return(View()); } }
public async Task <IActionResult> Atualizar([FromBody] UpdateEmpresaCommand command) { var updateEmpresaResult = await Mediator.Send(command); return(Ok(updateEmpresaResult)); }