refine filter
This commit is contained in:
parent
9d698fc79d
commit
fa769227e0
|
|
@ -278,50 +278,63 @@ public partial class MongoRepository
|
||||||
public List<Agent> GetAgents(AgentFilter filter)
|
public List<Agent> GetAgents(AgentFilter filter)
|
||||||
{
|
{
|
||||||
var agents = new List<Agent>();
|
var agents = new List<Agent>();
|
||||||
IQueryable<AgentDocument> query = _dc.Agents.AsQueryable();
|
var builder = Builders<AgentDocument>.Filter;
|
||||||
|
var filters = new List<FilterDefinition<AgentDocument>>() { builder.Empty };
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filter.AgentName))
|
if (!string.IsNullOrEmpty(filter.AgentName))
|
||||||
{
|
{
|
||||||
query = query.Where(x => x.Name.ToLower() == filter.AgentName.ToLower());
|
filters.Add(builder.Eq(x => x.Name, filter.AgentName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.Disabled.HasValue)
|
if (filter.Disabled.HasValue)
|
||||||
{
|
{
|
||||||
query = query.Where(x => x.Disabled == filter.Disabled);
|
filters.Add(builder.Eq(x => x.Disabled, filter.Disabled.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.AllowRouting.HasValue)
|
if (filter.AllowRouting.HasValue)
|
||||||
{
|
{
|
||||||
query = query.Where(x => x.AllowRouting == filter.AllowRouting);
|
filters.Add(builder.Eq(x => x.AllowRouting, filter.AllowRouting.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.IsPublic.HasValue)
|
if (filter.IsPublic.HasValue)
|
||||||
{
|
{
|
||||||
query = query.Where(x => x.IsPublic == filter.IsPublic);
|
filters.Add(builder.Eq(x => x.IsPublic, filter.IsPublic.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.IsRouter.HasValue)
|
if (filter.IsRouter.HasValue)
|
||||||
{
|
{
|
||||||
var route = _services.GetRequiredService<RoutingSettings>();
|
var route = _services.GetRequiredService<RoutingSettings>();
|
||||||
query = filter.IsRouter.Value ?
|
if (filter.IsRouter.Value)
|
||||||
query.Where(x => route.AgentIds.Contains(x.Id)) :
|
{
|
||||||
query.Where(x => !route.AgentIds.Contains(x.Id));
|
filters.Add(builder.In(x => x.Id, route.AgentIds));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filters.Add(builder.Nin(x => x.Id, route.AgentIds));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.IsEvaluator.HasValue)
|
if (filter.IsEvaluator.HasValue)
|
||||||
{
|
{
|
||||||
var evaluate = _services.GetRequiredService<EvaluatorSetting>();
|
var evaluate = _services.GetRequiredService<EvaluatorSetting>();
|
||||||
query = filter.IsEvaluator.Value ?
|
if (filter.IsEvaluator.Value)
|
||||||
query.Where(x => x.Id == evaluate.AgentId) :
|
{
|
||||||
query.Where(x => x.Id != evaluate.AgentId);
|
filters.Add(builder.Eq(x => x.Id, evaluate.AgentId));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filters.Add(builder.Ne(x => x.Id, evaluate.AgentId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.AgentIds != null)
|
if (filter.AgentIds != null)
|
||||||
{
|
{
|
||||||
query = query.Where(x => filter.AgentIds.Contains(x.Id));
|
filters.Add(builder.In(x => x.Id, filter.AgentIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
return query.ToList().Select(x => new Agent
|
var agentDocs = _dc.Agents.Find(builder.And(filters)).ToList();
|
||||||
|
|
||||||
|
return agentDocs.Select(x => new Agent
|
||||||
{
|
{
|
||||||
Id = x.Id,
|
Id = x.Id,
|
||||||
Name = x.Name,
|
Name = x.Name,
|
||||||
|
|
|
||||||
|
|
@ -206,21 +206,21 @@ public partial class MongoRepository
|
||||||
|
|
||||||
public List<Conversation> GetConversations(ConversationFilter filter)
|
public List<Conversation> GetConversations(ConversationFilter filter)
|
||||||
{
|
{
|
||||||
var records = new List<Conversation>();
|
var conversations = new List<Conversation>();
|
||||||
var builder = Builders<ConversationDocument>.Filter;
|
var builder = Builders<ConversationDocument>.Filter;
|
||||||
var filters = new List<FilterDefinition<ConversationDocument>>();
|
var filters = new List<FilterDefinition<ConversationDocument>>() { builder.Empty };
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(filter.AgentId)) filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
|
if (!string.IsNullOrEmpty(filter.AgentId)) filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
|
||||||
if (!string.IsNullOrEmpty(filter.Status)) filters.Add(builder.Eq(x => x.Status, filter.Status));
|
if (!string.IsNullOrEmpty(filter.Status)) filters.Add(builder.Eq(x => x.Status, filter.Status));
|
||||||
if (!string.IsNullOrEmpty(filter.Channel)) filters.Add(builder.Eq(x => x.Channel, filter.Channel));
|
if (!string.IsNullOrEmpty(filter.Channel)) filters.Add(builder.Eq(x => x.Channel, filter.Channel));
|
||||||
if (!string.IsNullOrEmpty(filter.UserId)) filters.Add(builder.Eq(x => x.UserId, filter.UserId));
|
if (!string.IsNullOrEmpty(filter.UserId)) filters.Add(builder.Eq(x => x.UserId, filter.UserId));
|
||||||
|
|
||||||
var conversations = _dc.Conversations.Find(builder.And(filters)).ToList();
|
var conversationDocs = _dc.Conversations.Find(builder.And(filters)).ToList();
|
||||||
|
|
||||||
foreach (var conv in conversations)
|
foreach (var conv in conversationDocs)
|
||||||
{
|
{
|
||||||
var convId = conv.Id.ToString();
|
var convId = conv.Id.ToString();
|
||||||
records.Add(new Conversation
|
conversations.Add(new Conversation
|
||||||
{
|
{
|
||||||
Id = convId,
|
Id = convId,
|
||||||
AgentId = conv.AgentId.ToString(),
|
AgentId = conv.AgentId.ToString(),
|
||||||
|
|
@ -233,7 +233,7 @@ public partial class MongoRepository
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return records;
|
return conversations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Conversation> GetLastConversations()
|
public List<Conversation> GetLastConversations()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue