//This Function takes the response and returns the response public static string Response(string topic) { using (Elderbot.Models.BotDataModel db = new Elderbot.Models.BotDataModel()) { //We need to add someway of ensure we only pull one and only one row and if no row is found //then we pull a I don't understand type response from the database. var q = db.BotResponses.Where(r => r.Topic == topic) .Select(r => new { r.Response }); foreach (var row in q) { return(row.Response.ToString()); } return("I don't have this intent in my database. That's embarassing."); } }
public static void WriteToDatabase(string conversationid, string username, string channel, string message) { //Instantiate entity frameowork connection Elderbot.Models.BotDataModel db = new Elderbot.Models.BotDataModel(); //Create a new MessageLog Object Elderbot.Models.MessageLog NewMsgLog = new Elderbot.Models.MessageLog { // Set the properties on the UserLog object ConversationId = conversationid, UserName = username, Channel = channel, Message = message,//Need to truncate to 500 chracters but doesn't work right now. Created = DateTime.UtcNow }; //Add the NewMsgLog Object to the actual Database db.MessageLogs.Add(NewMsgLog); db.SaveChanges(); }