diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index cd8f353b..43559232 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -13,7 +13,9 @@ public partial class AgentService { var record = (from a in db.Agent join ua in db.UserAgent on a.Id equals ua.AgentId - where ua.UserId == _user.Id && a.Id == agent.Id + join u in db.User on ua.UserId equals u.Id + where (ua.UserId == _user.Id || u.ExternalId == _user.Id) && + a.Id == agent.Id select a).First(); record.Name = agent.Name; diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index c1688a4c..b6963794 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -82,7 +82,7 @@ public class FileRepository : IBotSharpRepository var file = Path.Combine(d, "agents.json"); if (Directory.Exists(d) && File.Exists(file)) { - var json = File.ReadAllText(Path.Combine(d, "agents.json")); + var json = File.ReadAllText(file); _userAgents.AddRange(JsonSerializer.Deserialize>(json, _options)); } } @@ -205,11 +205,13 @@ public class FileRepository : IBotSharpRepository .Select(x => x.Key).ToList() .ForEach(uid => { - var dir = Path.Combine(_dbSettings.FileRepository, - "users", - uid); - var path = Path.Combine(dir, "agents.json"); - File.WriteAllText(path, JsonSerializer.Serialize(_userAgents.Where(x => x.UserId == uid), _options)); + var agents = _userAgents.Where(x => x.UserId == uid).ToList(); + if (agents.Any()) + { + var dir = Path.Combine(_dbSettings.FileRepository, "users", uid); + var path = Path.Combine(dir, "agents.json"); + File.WriteAllText(path, JsonSerializer.Serialize(agents, _options)); + } }); } }