- Chỉnh update users

- Đưa phần gọi lệnh đếm vào Task
This commit is contained in:
Nguyen Dinh Thuan
2024-09-20 06:36:56 +07:00
parent 2d474ef17f
commit 781e7e4f25
3 changed files with 79 additions and 45 deletions
+45 -1
View File
@@ -347,9 +347,20 @@ namespace SafeBagDE70
bResult = ResetCDMCounter();
}
break;
case 3:
if(IsInternetOk && !IsInTransaction)
{
Log.Information("Request update Customers");
int nCount = await UpdateCustomers();
Log.Information($"Updated {nCount} users");
InitUsers();
if (nCount > 0) bResult = true;
}
break;
}
//
await APIModels.UpdateDeviceCommand(command.Id, bResult?1:-1);
if(bResult)
await APIModels.UpdateDeviceCommand(command.Id, bResult?1:0);
}
}
}
@@ -369,6 +380,39 @@ namespace SafeBagDE70
Log.Error("GetandExecuteCommands error: "+str);
}
}
public static async Task<int> UpdateCustomers()
{
try
{
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();
}
return amCustomers.Count();
}
catch(Exception ex)
{
}
return 0;
}
public static bool ResetCDMCounter()
{
bool bResetOk = false;