temp save

This commit is contained in:
Jicheng Lu 2024-11-04 00:00:32 -06:00
parent 0addd38ce4
commit 7c34dbc0a7
2 changed files with 25 additions and 9 deletions

View file

@ -1,4 +1,5 @@
using BotSharp.Abstraction.Tasks.Models;
using BotSharp.Abstraction.Users.Enums;
using System.IO;
using System.Text.RegularExpressions;
@ -25,6 +26,20 @@ public partial class AgentService
var user = _db.GetUserById(_user.Id);
_db.BulkInsertAgents(new List<Agent> { agentRecord });
if (!UserConstant.AdminRoles.Contains(user.Role))
{
_db.BulkInsertUserAgents(new List<UserAgent>
{
new UserAgent
{
UserId = user.Id,
AgentId = agent.Id,
Actions = new List<string> { UserAction.Edit },
CreatedTime = DateTime.UtcNow,
UpdatedTime = DateTime.UtcNow
}
});
}
Utilities.ClearCache();
return await Task.FromResult(agentRecord);

View file

@ -429,15 +429,16 @@ public partial class MongoRepository
{
if (userAgents.IsNullOrEmpty()) return;
var userAgentDocs = userAgents.Select(x => new UserAgentDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
UserId = !string.IsNullOrEmpty(x.UserId) ? x.UserId : string.Empty,
AgentId = x.AgentId,
Actions = x.Actions,
CreatedTime = x.CreatedTime,
UpdatedTime = x.UpdatedTime
}).ToList();
var userAgentDocs = userAgents.Where(x => !string.IsNullOrEmpty(x.UserId))
.Select(x => new UserAgentDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
UserId = x.UserId,
AgentId = x.AgentId,
Actions = x.Actions,
CreatedTime = x.CreatedTime,
UpdatedTime = x.UpdatedTime
}).ToList();
_dc.UserAgents.InsertMany(userAgentDocs);
}