diff --git a/Bot.Rasa.RestApi/AgentController.cs b/Bot.Rasa.RestApi/AgentController.cs
index 49f5991a..34843c60 100644
--- a/Bot.Rasa.RestApi/AgentController.cs
+++ b/Bot.Rasa.RestApi/AgentController.cs
@@ -1,8 +1,10 @@
using Bot.Rasa.Agents;
using Bot.Rasa.Console;
+using EntityFrameworkCore.BootKit;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
namespace Bot.Rasa.RestApi
@@ -19,10 +21,10 @@ namespace Bot.Rasa.RestApi
[HttpPost]
public String Create([FromBody] Agent agent)
{
+ var console = new RasaConsole(dc);
+
dc.DbTran(() => {
-
-
-
+ console.CreateAgent(agent);
});
return agent.Id;
diff --git a/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj b/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj
index 3813d93c..dcb02a5a 100644
--- a/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj
+++ b/Bot.Rasa.RestApi/Bot.Rasa.RestApi.csproj
@@ -2,6 +2,7 @@
netcoreapp2.0
+ true
@@ -9,6 +10,8 @@
+
+
diff --git a/Bot.Rasa.RestApi/EntityItemController.cs b/Bot.Rasa.RestApi/EntityItemController.cs
new file mode 100644
index 00000000..b4094dae
--- /dev/null
+++ b/Bot.Rasa.RestApi/EntityItemController.cs
@@ -0,0 +1,16 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Bot.Rasa.RestApi
+{
+ public class EntityItemController : EssentialController
+ {
+ [HttpPost]
+ public IActionResult CreateEntity()
+ {
+ return Ok();
+ }
+ }
+}
diff --git a/Bot.Rasa.RestApi/EntityTypeController.cs b/Bot.Rasa.RestApi/EntityTypeController.cs
new file mode 100644
index 00000000..8b3f653a
--- /dev/null
+++ b/Bot.Rasa.RestApi/EntityTypeController.cs
@@ -0,0 +1,31 @@
+using Bot.Rasa.Agents;
+using Bot.Rasa.Entities;
+using EntityFrameworkCore.BootKit;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Bot.Rasa.RestApi
+{
+ public class EntityTypeController : EssentialController
+ {
+ [HttpPost]
+ public string CreateType([FromBody] EntityType entityType)
+ {
+ var agent = dc.Table().Find(entityType.AgentId);
+ dc.DbTran(() => agent.CreateEntityType(dc, entityType));
+
+ return entityType.Id;
+ }
+
+ [HttpDelete("{agentId}/{entityTypeId}")]
+ public IActionResult DeleteType([FromRoute] String agentId, [FromRoute] String entityTypeId)
+ {
+ var agent = dc.Table().Find(agentId);
+ dc.DbTran(() => agent.DeleteEntityType(dc, entityTypeId));
+
+ return Ok();
+ }
+ }
+}
diff --git a/Bot.Rasa.RestApi/EssentialController.cs b/Bot.Rasa.RestApi/EssentialController.cs
index 21b3543a..ea322c6c 100644
--- a/Bot.Rasa.RestApi/EssentialController.cs
+++ b/Bot.Rasa.RestApi/EssentialController.cs
@@ -1,8 +1,10 @@
using Bot.Rasa.Console;
+using DotNetToolkit;
using EntityFrameworkCore.BootKit;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.Sqlite;
using MySql.Data.MySqlClient;
+using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
@@ -63,5 +65,19 @@ namespace Bot.Rasa.RestApi
}
}
+ [HttpPatch("{table}/{id}")]
+ public IActionResult Patch([FromRoute] String table, [FromRoute] String id, [FromBody] JObject jObject)
+ {
+ var patch = new DbPatchModel
+ {
+ Table = table,
+ Id = id,
+ Values = jObject.ToDictionary()
+ };
+
+ dc.Patch(patch);
+
+ return Ok();
+ }
}
}
diff --git a/Bot.Rasa.RestApi/IntentController.cs b/Bot.Rasa.RestApi/IntentController.cs
new file mode 100644
index 00000000..de1ec468
--- /dev/null
+++ b/Bot.Rasa.RestApi/IntentController.cs
@@ -0,0 +1,26 @@
+using Bot.Rasa.Agents;
+using Bot.Rasa.Intents;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Bot.Rasa.RestApi
+{
+ public class IntentController : EssentialController
+ {
+ ///
+ /// User intent, a intent is connected to a dialog flow.
+ ///
+ ///
+ ///
+ ///
+ [HttpPost("{agentId}")]
+ public string CreateIntent([FromRoute] String agentId, [FromBody] Intent intent)
+ {
+ var agent = dc.Agent(agentId);
+
+ return intent.Id;
+ }
+ }
+}
diff --git a/Bot.Rasa/Agents/AgentExtension.cs b/Bot.Rasa/Agents/AgentExtension.cs
index 75908fe1..b35dc6ee 100644
--- a/Bot.Rasa/Agents/AgentExtension.cs
+++ b/Bot.Rasa/Agents/AgentExtension.cs
@@ -1,4 +1,5 @@
using Bot.Rasa.Entities;
+using Bot.Rasa.Intents;
using Bot.Rasa.Models;
using EntityFrameworkCore.BootKit;
using Microsoft.EntityFrameworkCore;
@@ -11,6 +12,17 @@ namespace Bot.Rasa.Agents
{
public static class AgentExtension
{
+ ///
+ /// Get agent header row from Agent table
+ ///
+ ///
+ ///
+ ///
+ public static Agent Agent(this Database dc, string agentId)
+ {
+ return dc.Table().Find(agentId);
+ }
+
public static String CreateEntity(this Agent agent, EntityType entity, Database dc)
{
return entity.Id;
@@ -23,7 +35,7 @@ namespace Bot.Rasa.Agents
UserSays = new List()
};
- var intents = dc.Intent().Include(x => x.Expressions).ToList();
+ var intents = dc.Table().Include(x => x.Expressions).ToList();
intents.ForEach(intent => {
diff --git a/Bot.Rasa/Bot.Rasa.csproj b/Bot.Rasa/Bot.Rasa.csproj
index 102c72f2..1aa114b2 100644
--- a/Bot.Rasa/Bot.Rasa.csproj
+++ b/Bot.Rasa/Bot.Rasa.csproj
@@ -2,10 +2,11 @@
netcoreapp2.0
+ true
-
+
diff --git a/Bot.Rasa/Console/RasaConsole.cs b/Bot.Rasa/Console/RasaConsole.cs
index fb218d5e..04331388 100644
--- a/Bot.Rasa/Console/RasaConsole.cs
+++ b/Bot.Rasa/Console/RasaConsole.cs
@@ -66,14 +66,14 @@ namespace Bot.Rasa.Console
public Agent LoadAgent(String agentId)
{
- return dc.Agent().Include(x => x.Intents).FirstOrDefault(x => x.Id == agentId);
+ return dc.Table().Include(x => x.Intents).FirstOrDefault(x => x.Id == agentId);
}
public String CreateAgent(Agent agent)
{
- if (dc.Agent().Any(x => x.Name == agent.Name)) return String.Empty;
+ if (dc.Table().Any(x => x.Id == agent.Id)) return String.Empty;
- dc.Agent().Add(agent);
+ dc.Table().Add(agent);
return agent.Id;
}
diff --git a/Bot.Rasa/Console/RequestExtension.cs b/Bot.Rasa/Console/RequestExtension.cs
index 7ab49ff8..0d35244b 100644
--- a/Bot.Rasa/Console/RequestExtension.cs
+++ b/Bot.Rasa/Console/RequestExtension.cs
@@ -39,7 +39,7 @@ namespace Bot.Rasa.Console
///
public static bool Train(this RasaConsole console, Database dc, String agentId)
{
- var agent = dc.Agent().Find(agentId);
+ var agent = dc.Table().Find(agentId);
var corpus = agent.GrabCorpus(dc);
string json = JsonConvert.SerializeObject(new { rasa_nlu_data = corpus },
diff --git a/Bot.Rasa/Entities/EntityType.cs b/Bot.Rasa/Entities/EntityType.cs
index 9798621a..ca2838f5 100644
--- a/Bot.Rasa/Entities/EntityType.cs
+++ b/Bot.Rasa/Entities/EntityType.cs
@@ -14,6 +14,7 @@ namespace Bot.Rasa.Entities
[StringLength(36)]
public String AgentId { get; set; }
+ [Required]
[MaxLength(64)]
public String Name { get; set; }
diff --git a/Bot.Rasa/Entities/EntityTypeExtension.cs b/Bot.Rasa/Entities/EntityTypeExtension.cs
new file mode 100644
index 00000000..cefde8b0
--- /dev/null
+++ b/Bot.Rasa/Entities/EntityTypeExtension.cs
@@ -0,0 +1,29 @@
+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, EntityType entityType)
+ {
+ if (dc.Table().Any(x => x.Name == entityType.Name && x.AgentId == agent.Id)) return agent.Id;
+
+ dc.Table().Add(entityType);
+
+ return entityType.Id;
+ }
+
+ public static void DeleteEntityType(this Agent agent, Database dc, String entityTypeId)
+ {
+ var entityType = dc.Table().FirstOrDefault(x => x.Id == entityTypeId);
+ if (entityType == null) return;
+
+ dc.Table().Remove(entityType);
+ }
+ }
+}
diff --git a/Bot.Rasa/EntityDbContextExtension.cs b/Bot.Rasa/EntityDbContextExtension.cs
deleted file mode 100644
index 5c0cad18..00000000
--- a/Bot.Rasa/EntityDbContextExtension.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Bot.Rasa.Agents;
-using Bot.Rasa.Intents;
-using EntityFrameworkCore.BootKit;
-using Microsoft.EntityFrameworkCore;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Bot.Rasa
-{
- public static class EntityDbContextExtension
- {
- public static DbSet Agent(this Database dc)
- {
- return dc.Table();
- }
-
- public static DbSet Intent(this Database dc)
- {
- return dc.Table();
- }
-
- public static DbSet IntentExpression(this Database dc)
- {
- return dc.Table();
- }
- }
-}
diff --git a/Bot.Rasa/Intents/Intent.cs b/Bot.Rasa/Intents/Intent.cs
index 99ed6839..0a39a823 100644
--- a/Bot.Rasa/Intents/Intent.cs
+++ b/Bot.Rasa/Intents/Intent.cs
@@ -7,6 +7,9 @@ using System.Text;
namespace Bot.Rasa.Intents
{
+ ///
+ /// Intent Table
+ ///
[Table("Bot_Intent")]
public class Intent : DbRecord, IDbRecord
{
diff --git a/Bot.Rasa/Intents/IntentExtension.cs b/Bot.Rasa/Intents/IntentExtension.cs
new file mode 100644
index 00000000..002990f6
--- /dev/null
+++ b/Bot.Rasa/Intents/IntentExtension.cs
@@ -0,0 +1,21 @@
+using Bot.Rasa.Agents;
+using EntityFrameworkCore.BootKit;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Bot.Rasa.Intents
+{
+ public static class IntentExtension
+ {
+ public static string CreateIntent(this Agent agent, Database dc, Intent intent)
+ {
+ if (dc.Table().Any(x => x.Id == intent.Id)) return intent.Id;
+
+ dc.Table().Add(intent);
+
+ return intent.Id;
+ }
+ }
+}
diff --git a/Bot.UnitTest/AgentTest.cs b/Bot.UnitTest/AgentTest.cs
index 16f6ba2d..8c7597b9 100644
--- a/Bot.UnitTest/AgentTest.cs
+++ b/Bot.UnitTest/AgentTest.cs
@@ -26,7 +26,7 @@ namespace Bot.UnitTest
if(row > 0)
{
- //var result = rasa.Train(dc, agent.Id);
+ var result = rasa.Train(dc, agent.Id);
}
var loadedAgent = rasa.LoadAgent(agent.Id);
@@ -41,7 +41,7 @@ namespace Bot.UnitTest
{
var rasa = new RasaConsole(dc);
var response = rasa.TextRequest(PIZZA_BOT_ID, "how old are you");
- response = rasa.TextRequest(PIZZA_BOT_ID, "where do you come from");
+ response = rasa.TextRequest(PIZZA_BOT_ID, "where are you from");
response = rasa.TextRequest(PIZZA_BOT_ID, "would you like some cookie");
}