43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using Gremlin_Blazor.Models;
|
|
using MySqlConnector;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
|
|
namespace Gremlin_Blazor.Data
|
|
{
|
|
public class DataAccessService
|
|
{
|
|
public DataAccessService() { }
|
|
|
|
private static string ConnectionString => ($"Server=woitschetzki.de;Database=Gremlin;User ID=sascha;Password=mgltoJtmmDnKJ86LltsGdw;Trusted_Connection=False;MultipleActiveResultSets=true;");
|
|
|
|
public static async Task<List<Contact>> GetContactsFromDb()
|
|
{
|
|
List<Contact> contacts = new();
|
|
DataTable dataTable = new();
|
|
|
|
MySqlConnection connection = new(ConnectionString);
|
|
MySqlDataAdapter dataAdapter = new("select * from [Gremlin].[Contacts]", connection);
|
|
int rows = dataAdapter.Fill(dataTable);
|
|
Debug.WriteLine($"Succesfully added {rows} rows to DataAtapter");
|
|
|
|
foreach (DataRow row in dataTable.Rows)
|
|
{
|
|
Contact contact = new()
|
|
{
|
|
ContactId = Convert.ToInt32(row["ContactId"]),
|
|
AccountId = Convert.ToInt32(row["AccountId"]),
|
|
FirstName = row["FirstName"] as string,
|
|
LastName = row["LastName"] as string,
|
|
Gender = Convert.ToInt32(row["Gender"]),
|
|
EMail = row["Email"] as string
|
|
};
|
|
contacts.Add(contact);
|
|
}
|
|
return await Task.FromResult(contacts);
|
|
}
|
|
|
|
}
|
|
}
|
|
|