BotSharp/Bot.Rasa/Entities/EntityTypeExtension.cs

30 lines
854 B
C#
Raw Normal View History

2018-01-02 18:05:35 +00:00
using Bot.Rasa.Agents;
using EntityFrameworkCore.BootKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bot.Rasa.Entities
{
public static class EntityTypeExtension
{
public static string CreateEntityType(this Agent agent, Database dc, Entity entityType)
2018-01-02 18:05:35 +00:00
{
if (dc.Table<Entity>().Any(x => x.Name == entityType.Name && x.AgentId == agent.Id)) return agent.Id;
2018-01-02 18:05:35 +00:00
dc.Table<Entity>().Add(entityType);
2018-01-02 18:05:35 +00:00
return entityType.Id;
}
public static void DeleteEntityType(this Agent agent, Database dc, String entityTypeId)
{
var entityType = dc.Table<Entity>().FirstOrDefault(x => x.Id == entityTypeId);
2018-01-02 18:05:35 +00:00
if (entityType == null) return;
dc.Table<Entity>().Remove(entityType);
2018-01-02 18:05:35 +00:00
}
}
}