public CommandResult Criar(CriarContratoCommand command) { string entityName = "Contrato"; { try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Cliente cliente = dataContext.Cliente.FirstOrDefault(c => c.Cod_Cliente == command.CodCliente); if (cliente is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.CodCliente))); } Contrato contrato = Contrato.Criar( command.ColetaContratada, command.ValorLimite, command.ValorUnidade, DataString.FromNullableString(command.MotivoCancelamento), command.DataCancelamento, command.FlagTermino, command.DataInicio, command.DataTermino, cliente); dataContext.Add(contrato); dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } } }
public IActionResult Criar( [FromServices] IContratoService service, [FromBody] CriarContratoCommand command) { return(Result(service.Criar(command))); }