- Chỉnh update users
- Đưa phần gọi lệnh đếm vào Task
This commit is contained in:
+45
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user