diff --git a/Admin/UserManageUC.xaml.cs b/Admin/UserManageUC.xaml.cs index 937b622..4450369 100644 --- a/Admin/UserManageUC.xaml.cs +++ b/Admin/UserManageUC.xaml.cs @@ -42,29 +42,39 @@ namespace SafeBagDE70.Admin { try { - var amCustomers = await APIModels.GetAeonMallCustomers(AppData.TenantId); - using (var context = new CDMDbContext()) + if(AppData.IsInTransaction) { - var customers = context.Customers; - context.Customers.RemoveRange(customers); - context.SaveChanges(); - foreach (var amCustomer in amCustomers) - { - var customer = new Customer - { - AccountNumber = amCustomer.TenantCode, - AccountHolder = amCustomer.TenantName, - TenantName = amCustomer.TenantShortName, - TenantCode = amCustomer.TenantCode, - PinCode = amCustomer.TenantCode, - UpdatedTime = DateTime.Now, - }; - customers.Add(customer); - } - context.SaveChanges(); + lblStatus.Foreground = new SolidColorBrush(Colors.Red); + lblStatus.Content = "Vui lòng kết thúc giao dịch để thực hiện chức năng này"; + } - lblStatus.Foreground = new SolidColorBrush(Colors.Green); - lblStatus.Content = "Updated customers: " + amCustomers.Count; + else + { + var amCustomers = await APIModels.GetAeonMallCustomers(AppData.TenantId); + using (var context = new CDMDbContext()) + { + var customers = context.Customers; + context.Customers.RemoveRange(customers); + context.SaveChanges(); + foreach (var amCustomer in amCustomers) + { + var customer = new Customer + { + AccountNumber = amCustomer.TenantCode, + AccountHolder = amCustomer.TenantName, + TenantName = amCustomer.TenantShortName, + TenantCode = amCustomer.TenantCode, + PinCode = amCustomer.TenantCode, + UpdatedTime = DateTime.Now, + }; + customers.Add(customer); + } + context.SaveChanges(); + } + lblStatus.Foreground = new SolidColorBrush(Colors.Green); + lblStatus.Content = "Updated customers: " + amCustomers.Count; + } + AppData.InitUsers(); } catch(Exception ex) { diff --git a/AppData.cs b/AppData.cs index b36fa23..1bacbe7 100644 --- a/AppData.cs +++ b/AppData.cs @@ -68,7 +68,7 @@ namespace SafeBagDE70 } - private static bool InitUsers() + public static bool InitUsers() { int retryCount = 0; int maxRetries = 20; // Max retries before giving up