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 | 73<br />

Check if a User is an Expert<br />

The simplest way to check if a User is an Expert is to get an Expert based on the user we want to check using the<br />

GetExpert method of the ExpertHandler. If the function returns an ExpertMember object, it means that the user is an<br />

expert; if it returns null, the user is not an expert, as no expert with that unique user id exists in the database.<br />

// Get the user to check by id<br />

IUser user = (IUser)StarCommunitySystem.<br />

CurrentContext.DefaultSecurity.GetUser(1234);<br />

bool isExpert = false;<br />

// Try to retrieve an expert<br />

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

// if returned expert object is not null, the user is an expert<br />

if ( expert != null )<br />

isExpert = true;<br />

2.18.5 Add a Question<br />

The purpose of experts existence in the community is simply to answer questions. However, before they can do so, a<br />

question has to be asked. In this section, we will show how a user can add a question to an Expert.<br />

Import Necessary Namespaces<br />

First, import the necessary namespaces that will be used to ask a question by a user. The namespaces<br />

StarCommunity.Core, StarCommunity.Core.Modules.Security and StarCommunity.Modules.Expert are described by<br />

clicking on their respective names. Make sure you add the assembly as a reference, mentioned in section 1.1.1.<br />

using StarCommunity.Core;<br />

using StarCommunity.Core.Modules;<br />

using StarCommunity.Core.Modules.Security;<br />

using StarCommunity.Modules.Expert;<br />

Add a Question<br />

To add a question, first a Questioncode object has to be created. To create it, we need to provide question header,<br />

question body, the status of the question and the author of the question. Question header and body are strings that<br />

define the question; the question status can be one of: New, Assigned, Published, Revoked or Rejected. For new<br />

questions, it is best to set the status to New. Question author can be one of: UserAuthor (community User is the<br />

author of the question), AnonymousAuthor (community User is the author, but does not want to be identified by other<br />

community members) and GuestAuthor (has no underlying user).<br />

© <strong>EPiServer</strong> AB

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

Saved successfully!

Ooh no, something went wrong!