Fix user agents in FileRepository.
This commit is contained in:
parent
53856535dc
commit
0fe0f1db79
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<List<UserAgentRecord>>(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));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue