31.10.2014 Views

Developer's Guide - EPiServer World

Developer's Guide - EPiServer World

Developer's Guide - EPiServer World

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Tutorials | 75<br />

Assign a Question<br />

To assign a question, an AssignedQuestion object has to be created. Objects of this class bind questions to experts, and<br />

allow for assigning a forum topic that relates to the question.<br />

// Get a question from database<br />

Question question = ExpertHandler.GetQuestion(322);<br />

// Get an expert from database<br />

ExpertBase expert = ExpertHandler.GetExpert(994);<br />

// Create AssignedQuestion<br />

AssignedQuestion asgndQstn = new AssignedQuestion(question, expert);<br />

// Add the assignment to the database;<br />

// the returned AssignedQuestion has ID property set<br />

asgndQstn = ExpertHandler.AddAssignedQuestion(asgndQstn);<br />

2.18.7 Answer a Question<br />

When a question has been assigned to an expert, it can be answered. If the Expert module have the AutoPublish<br />

property set to true, the question status is automatically changed to Published if it was in New or Assigned state. Below<br />

you can find a short example of how to add an answer to a question.<br />

Import Necessary Namespaces<br />

First, import the necessary namespaces that will be used to answer a question. The namespace<br />

StarCommunity.Modules.Expert is described by clicking on its name. Make sure you add the assembly as a reference,<br />

mentioned in section 1.1.1.<br />

using StarCommunity.Modules.Expert;<br />

Answer a Question<br />

To answer a question, an Answer object has to be created. Answer object has a reference to the AssignedQuestion<br />

object, therefore both the question and the expert answering the question are always known. When the Answer object<br />

has been created, it has to be committed to database using the AddAnswer method of the ExpertHandler class.<br />

// Get an assinged question from database<br />

AssignedQuestion asgndQstn = ExpertHandler.GetAssignedQuestion(987);<br />

// Create an answer, initially in "not approved" state<br />

Answer answer = new Answer("Answer header", "The answer itself",<br />

AnswerStatus.NotApproved, asgndQstn);<br />

// Add answer to the database;<br />

// the returned Answer object has its ID property set<br />

answer = ExpertHandler.AddAnswer(answer);<br />

© <strong>EPiServer</strong> AB

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!