//Update public void Update(QuestionsBTO existingQuestions) { UnitOfWork unitOfWork = new UnitOfWork(context); unitOfWork.QuestionsRepo.Update(existingQuestions.QuestionsBTOToQuestions()); unitOfWork.Save(); }
//Create public QuestionsBTO Create(QuestionsBTO bto) { UnitOfWork unitOfWork = new UnitOfWork(context); var response = unitOfWork.QuestionsRepo.Create(bto.QuestionsBTOToQuestions()); unitOfWork.Save(); return(response.QuestionsToQuestionsBTO()); }
public static Questions QuestionsBTOToQuestions(this QuestionsBTO bto) { return(new Questions { Id = bto.id, Description = bto.question, Status = bto.status, Answer = bto.answer }); }
public IHttpActionResult Post(QuestionsBTO questionBto) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } QuestionsLogic questions = new QuestionsLogic(); var model = questions.Create(questionBto); return(CreatedAtRoute("DefaultApi", new { id = model.id }, model)); }
//ReadAll public List <QuestionsBTO> RetrieveAll() { UnitOfWork unitOfWork = new UnitOfWork(context); List <QuestionsBTO> Listbto = new List <QuestionsBTO>(); foreach (var item in unitOfWork.QuestionsRepo.RetrieveAll()) { QuestionsBTO btoToAdd = this.Retrieve(item.Id); Listbto.Add(btoToAdd); } return(Listbto); }
public IHttpActionResult GetAnswer(string question) { DirectLineClient client = new DirectLineClient(directLineSecret); var conversation = System.Web.HttpContext.Current.Session["conversation"] as Conversation; if (conversation == null) { conversation = client.Conversations.StartConversation(); } Activity message = new Activity { From = new ChannelAccount(fromUser), Text = question, Type = ActivityTypes.Message }; client.Conversations.PostActivity(conversation.ConversationId, message); var msg = client.Conversations.GetActivities(conversation.ConversationId); var msgT = from m in msg.Activities where m.From.Id == botId select m; var rep = msgT.Last().Text; QuestionsBTO questionsBTO = new QuestionsBTO(); questionsBTO.question = question; questionsBTO.answer = rep; string s = "No QnA Maker answers were found. This example uses a QnA Maker Knowledge Base that focuses on smart light bulbs.\r\n To see QnA Maker in action, ask the bot questions like 'Why won't it turn on?' or 'I need help'."; if (questionsBTO.answer == s) { questionsBTO.answer = "We can't help you for the moment, contact us at [email protected] for more information!"; if (questionsBTO.status == null) { questionsBTO.status = "no answer"; } var contoller = new QuestionsController(); contoller.Post(questionsBTO); } System.Web.HttpContext.Current.Session["conversation"] = conversation; return(Ok(questionsBTO)); }
public IHttpActionResult Put(QuestionsBTO questionBto) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } QuestionsLogic questions = new QuestionsLogic(); var existingQuestions = questions.Retrieve(questionBto.id); if (existingQuestions != null) { questions.Update(questionBto); } else { return(NotFound()); } return(Ok()); }