Click or drag to resize
Askia

IContext Interface

Provide a context for requests execution, it's required for many API requests.
The context is created and its members values are filled by the software using AskiaCore, most of them help identify an entity by providing an id.

Namespace:  AskiaCore
Assembly:  AskiaCore (in AskiaCore.dll) Version: 6.0.0-build000000000000000000000000000000000000000001
Syntax
public interface IContext

The IContext type exposes the following members.

Properties
  NameDescription
Public propertyLanguageId
Id of the current survey language.
Public propertySessionId
Arbitrary session id in which the request is made. This session id should be the same for all requests made by a client session.
Public propertyUserId
Id of the user making the request.
Top
Examples

Create a new survey with one question

using AskiaCore;

namespace MyApp
{
    public class MyProgram
    {
        static void Main()
        {
            // Initialize the database connection string (Where the survey will be stored)
            Persistent.InitDatabaseConnection("connectionstring", DatabaseTypes.PORTAL);

            // Create a new context
            IContext context = ContextFactory.Create();
            context.UserId = 1;
            context.SessionId = "xxxxx-xxxxx-xxxxx-xxxxxx";
            context.LanguageId = 2057; // Edit the survey with this language (English)

            // Create a new survey
            ISurvey survey = SurveyFactory.Create(context);
            survey.Name = "MySurvey";
            survey.SetDefaultLanguageId(2057); // English

            // Create the single closed question gender
            IQuestion gender = survey.Questions.Create();
            gender.Shortcut = "gender";
            gender.MainCaption ="What's your gender?";
            gender.Type = QuestionType.Single;

            // Create responses
            IResponse man = gender.Responses.Create();
            man.MainCaption = "Man";
            IResponse woman = gender.Responses.Create();
            woman.MainCaption = "Woman";

            // Save all changes
            survey.SaveAll();

            // Release the database connection
            Persistent.EndDatabaseConnection();
        }
    }
}
See Also