using Marco.Pms.Model.Dtos.Authentication; 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; private readonly ApiService _loginApiService; // Replace with your actual API endpoint private const string DirectoryApiEndpoint = "http://localhost:5032/api/directory/create/list"; private const string LoginApiEndpoint = "http://localhost:5032/api/auth/login"; public MainWindow() { InitializeComponent(); _apiService = new ApiService(DirectoryApiEndpoint); _loginApiService = new ApiService(LoginApiEndpoint); _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."; } LoginDto loginDto = new LoginDto { Username = "admin@marcoaiot.com", Password = "User@123" }; string jwt = await _loginApiService.LoginAsync(loginDto); bool success = await _apiService.SendDataAsync(createContactDto, jwt); //foreach (Contacts contact in contactsData) //{ // //.Text = $"Sending {apiDataList.Count} records to API..."; // bool success = await _apiService.SendDataAsync(contact); //} } } }