feat: Aggiunta gestione nome database sorgente nei profili DataCoupler
✨ Nuove funzionalità: - Aggiunto campo SourceDatabaseName nella tabella DataCouplerProfiles - Implementato recupero automatico del nome database dalle credenziali - Migliorata applicazione profili con supporto database specifico - Aggiornata logica di connessione database con selezione database 🔧 Modifiche tecniche: - Aggiunta migration per colonna SourceDatabaseName - Estesi modelli DataCouplerProfile e DataCouplerProfileDto - Aggiornato DataCouplerProfileService per gestire nuovo campo - Modificato ProfileSaver per recupero automatico database name - Implementato metodo ConnectToDatabaseWithSpecificDatabase 🐛 Correzioni: - Migliorata gestione connessioni database multi-database - Corretta formattazione codice e spaziature - Rimosse linee vuote eccessive nel codice sorgente 🧪
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using CredentialManager.Models;
|
||||
using CredentialManager.Services;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Components;
|
||||
|
||||
public partial class ProfileSaver
|
||||
{
|
||||
[Inject] private ICredentialService CredentialService { get; set; } = default!;
|
||||
|
||||
[Parameter] public bool CanSave { get; set; }
|
||||
[Parameter] public string SourceType { get; set; } = "";
|
||||
[Parameter] public int? SourceCredentialId { get; set; }
|
||||
[Parameter] public string? SourceCredentialName { get; set; }
|
||||
[Parameter] public string? SourceDatabaseName { get; set; }
|
||||
[Parameter] public string? SourceSchema { get; set; }
|
||||
[Parameter] public string? SourceTable { get; set; }
|
||||
[Parameter] public string? SourceFilePath { get; set; }
|
||||
@@ -51,6 +55,9 @@ public partial class ProfileSaver
|
||||
|
||||
try
|
||||
{
|
||||
// Recupera automaticamente il nome del database dalla connessione attiva
|
||||
var sourceDatabaseName = await GetSourceDatabaseNameAsync();
|
||||
|
||||
var profileDto = new DataCouplerProfileDto
|
||||
{
|
||||
Name = ProfileData.Name,
|
||||
@@ -58,6 +65,7 @@ public partial class ProfileSaver
|
||||
SourceType = SourceType,
|
||||
SourceCredentialId = SourceCredentialId,
|
||||
SourceCredentialName = SourceCredentialName,
|
||||
SourceDatabaseName = sourceDatabaseName,
|
||||
SourceSchema = SourceSchema,
|
||||
SourceTable = SourceTable,
|
||||
SourceFilePath = SourceFilePath,
|
||||
@@ -119,6 +127,34 @@ public partial class ProfileSaver
|
||||
SaveMessageType = type;
|
||||
}
|
||||
|
||||
private async Task<string?> GetSourceDatabaseNameAsync()
|
||||
{
|
||||
// Prima priorità: se SourceDatabaseName è già impostato come parametro, usa quello
|
||||
if (!string.IsNullOrEmpty(SourceDatabaseName))
|
||||
{
|
||||
return SourceDatabaseName;
|
||||
}
|
||||
|
||||
// Seconda priorità: se abbiamo un SourceCredentialId, recupera il database dalle credenziali
|
||||
if (SourceCredentialId.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var credential = await CredentialService.GetDatabaseCredentialAsync(SourceCredentialId.Value);
|
||||
if (credential != null && !string.IsNullOrEmpty(credential.DatabaseName))
|
||||
{
|
||||
return credential.DatabaseName;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Se non riesce a recuperare le credenziali, continua con null
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public class ProfileFormModel
|
||||
{
|
||||
[Required(ErrorMessage = "Il nome del profilo è obbligatorio")]
|
||||
|
||||
Reference in New Issue
Block a user