using Marco.Pms.Model.Dtos.Directory; using Microsoft.Win32; using System.Windows; namespace Marco.Pms.UtilityApplication { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { //DirectoryHelper helper = new DirectoryHelper(); private readonly DirectoryHelper _directoryHelper; private readonly ApiService _apiService; // Replace with your actual API endpoint private const string ApiEndpoint = "https://your-api-url.com/api/data"; public MainWindow() { InitializeComponent(); _apiService = new ApiService(ApiEndpoint); _directoryHelper = new DirectoryHelper(); } private void btnFileUpload_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Excel files (*.xlsx)|*.xlsx|CSV files (*.csv)|*.csv"; // Optional: filter file types if (openFileDialog.ShowDialog() == true) { string filePath = openFileDialog.FileName; // Now you can use filePath to read or process the selected file txtFilePath.Text = filePath; //MessageBox.Show($"Selected file: {filePath}"); } } private async void btnSubmit_Click(object sender, RoutedEventArgs e) { List contactsData = null; List tagsMaster = null; List projectMaster = null; List categoryMasters = null; List createContactDto = null; List failedContacts = null; (contactsData, categoryMasters, tagsMaster, projectMaster) = await _directoryHelper.ReadExcelData(txtFilePath.Text); ( createContactDto, failedContacts) = await _directoryHelper.GenerateCreateContactDto(contactsData, categoryMasters, tagsMaster, projectMaster); // Check if there's data to display if (failedContacts != null && failedContacts.Any()) { // Assign the list to the DataGrid's ItemsSource ContactsDataGrid.ItemsSource = failedContacts; // You can optionally update a status text block // StatusTextBlock.Text = $"Displayed {importedContacts.Count} contacts."; } else { // Clear the DataGrid if no data ContactsDataGrid.ItemsSource = null; // StatusTextBlock.Text = "No contacts to display."; } foreach (Contacts contact in contactsData) { //.Text = $"Sending {apiDataList.Count} records to API..."; bool success = await _apiService.SendDataAsync(contact); } } } }