Exemple #1
0
    /// <summary>
    /// Binds values to Topic navigation bar.
    /// </summary>
    public void BindNavMenu(int lessonID, int userID)
    {
        TopicBL topics = new TopicBL();

        // Get all topics of this lesson.
        DataTable lessonTopics = topics.GetTopicsByLessonID(lessonID);

        // Filter for completed topics by the user.
        UserTopicBL userTopicBL = new UserTopicBL();


        DataTable userTopicRecord = null;

        foreach (DataRow row in lessonTopics.Rows)
        {
            // Create a list item.
            HtmlGenericControl listItemTitle = new HtmlGenericControl("li");

            // Retrieve UserTopic record by user ID
            int topicID = row.Field <int>("ID");
            userTopicRecord = userTopicBL.GetRecord(UserID, topicID);

            // If record not present insert a new one, linking user with topic.
            if (userTopicRecord.Rows.Count < 1)
            {
                userTopicBL.InsertRecord(UserID, topicID);
                userTopicRecord = userTopicBL.GetRecord(UserID, topicID);
            }

            // Declare a link button.
            LinkButton linkButton = new LinkButton();

            // Get completion date value.
            DateTime?date = userTopicRecord.Rows[0].Field <DateTime?>("DateCompleted");

            // If topic was not complete show white very good sign.
            if (date == null)
            {
                linkButton.Text = "<img src=http://localhost:3787/image/c1.jpg> " + row.Field <string>("Title").ToString();
            }
            // else show green very good sign.
            else
            {
                linkButton.Text = "<img src=http://localhost:3787/image/c2.jpg> " + row.Field <string>("Title").ToString();
            }

            linkButton.Attributes.Add("runat", "server");
            linkButton.CommandArgument = topicID.ToString();
            linkButton.Click          += new EventHandler(TopicRedirect);

            // Add link button to list item's controls.
            listItemTitle.Controls.Add(linkButton);

            // Add list item to unsorlted list controls.
            navSideMenu.Controls.Add(listItemTitle);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check if user has authorization.
        if (!Context.User.Identity.IsAuthenticated && Context.Session["UserID"] != null)
        {
            Response.Redirect("Login.aspx");
        }

        // Reference User ID
        UserID = Convert.ToInt32(Context.Session["UserID"]);

        // Validate Query strings.
        Validation();

        // Reference values stored in query strings.
        TopicID  = Convert.ToInt32(Request.QueryString["ID"]);
        LessonID = Convert.ToInt32(Request.QueryString["lessonid"]);

        // Create example tables according to the topic ID.
        BindExampleTable();

        // Create an instance of the Topic business logic
        TopicBL topicBL = new TopicBL();

        // Get the topic record by its ID from the database.
        DataTable dataTable = topicBL.GetTopicByID(TopicID);

        // Pass the video link to the Iframe instance.
        videoSource.Src = dataTable.Rows[0].Field <string>("VideoLink");

        // Get text content to populate the Topic page.
        BindContent(TopicID);

        if (!IsPostBack)
        {
            // Insert record if it doesn't exist in the linking table between user and topic.
            userTopicBL = new UserTopicBL();
            userTopicBL.InsertRecord(UserID, TopicID);
        }
    }