Fix BacktestCount
This commit is contained in:
@@ -134,7 +134,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
// Check if an entity with this key is already being tracked
|
||||
var trackedEntity = _context.ChangeTracker.Entries<AgentSummaryEntity>()
|
||||
.FirstOrDefault(e => e.Entity.Id == existing.Id);
|
||||
|
||||
|
||||
if (trackedEntity != null)
|
||||
{
|
||||
// Entity is already tracked, update its values
|
||||
@@ -147,7 +147,7 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
// Entity is not tracked, use Update method which handles state properly
|
||||
_context.AgentSummaries.Update(entityToUpdate);
|
||||
}
|
||||
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("AgentSummary updated for user {UserId} with agent name {AgentName}",
|
||||
@@ -316,14 +316,16 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
{
|
||||
entity.AgentName = agentName;
|
||||
entity.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
|
||||
_context.AgentSummaries.Update(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
_logger.LogInformation("Agent name updated for user {UserId} to {AgentName}", userId, agentName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No AgentSummary found for user {UserId} when trying to update agent name to {AgentName}",
|
||||
_logger.LogWarning(
|
||||
"No AgentSummary found for user {UserId} when trying to update agent name to {AgentName}",
|
||||
userId, agentName);
|
||||
}
|
||||
}
|
||||
@@ -340,17 +342,19 @@ public class AgentSummaryRepository : IAgentSummaryRepository
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.BacktestCount++;
|
||||
var newCount = entity.BacktestCount + 1;
|
||||
entity.BacktestCount = newCount;
|
||||
entity.UpdatedAt = DateTime.UtcNow;
|
||||
|
||||
|
||||
_context.AgentSummaries.Update(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Backtest count incremented for user {UserId} to {BacktestCount}",
|
||||
|
||||
_logger.LogInformation("Backtest count incremented for user {UserId} to {BacktestCount}",
|
||||
userId, entity.BacktestCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("No AgentSummary found for user {UserId} when trying to increment backtest count",
|
||||
_logger.LogWarning("No AgentSummary found for user {UserId} when trying to increment backtest count",
|
||||
userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user