using BotSharp.Abstraction.Agents; using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Users; namespace BotSharp.Core.Agents.Services; public class AgentService : IAgentService { private readonly IServiceProvider _services; private readonly IUserIdentity _user; public AgentService(IServiceProvider services, IUserIdentity user) { _services = services; _user = user; } public async Task CreateAgent(Agent agent) { var db = _services.GetRequiredService(); var record = db.Agent.FirstOrDefault(x => x.OwnerId == _user.Id && x.Name == agent.Name); if (record != null) { return record.ToAgent(); } record = AgentRecord.FromAgent(agent); record.Id = Guid.NewGuid().ToString(); record.OwnerId = _user.Id; record.CreatedDateTime = DateTime.UtcNow; record.UpdatedDateTime = DateTime.UtcNow; db.Transaction(delegate { db.Add(record); }); return record.ToAgent(); } public Task DeleteAgent(string id) { throw new NotImplementedException(); } public async Task> GetAgents() { var db = _services.GetRequiredService(); var query = from agent in db.Agent where agent.OwnerId == _user.Id select agent.ToAgent(); return query.ToList(); } public Task UpdateAgent(Agent agent) { throw new NotImplementedException(); } }