public CommandResult Atualizar(AtualizarMotoristaCommand command) { string entityName = "Motorista"; string commandName = $"Atualizando {entityName}"; try { command.Validate(); if (command.Invalid) { return(CommandResult.Invalid(command.Notifications.ToNotificationsString())); } Motorista motorista = dataContext.Motorista.FirstOrDefault(x => x.Cod_Motorista == command.Cod_Motorista); if (motorista is null) { return(CommandResult.Invalid(Logs.EntidadeNaoEncontrada(entityName, command.Cod_Motorista))); } if (dataContext.Motorista.Any(x => x.Nome == command.Nome.ToUpper() && x.Cod_Motorista != command.Cod_Motorista)) { string message = "Já existe um Motorista com este nome."; return(CommandResult.Invalid(message)); } motorista.Atualizar(DataString.FromString(command.Nome), DataString.FromNullableString(command.Ajudante1), DataString.FromNullableString(command.Ajudante2), DataString.FromString(command.Placa), DataString.FromNullableString(command.Telefone1), DataString.FromNullableString(command.Telefone2)); //if (material.HasNotifications) //{ // return CommandResult.Invalid(material.Notifications.ToNotificationsString()); //} dataContext.SaveChanges(); return(CommandResult.Valid()); } catch (Exception ex) { return(CommandResult.Invalid(ex.Message)); } }