public async Task <IHttpActionResult> PutTopicItem(int id, Topic item)
        {
            TopicBL topicBL = new TopicBL(_context);

            if (!id.Equals(item.topicID))
            {
                return(BadRequest());
            }

            else if (!topicBL.TopicExists(id))
            {
                var Id = await topicBL.CreateNewTopic(item);

                if (Id == null)
                {
                    return(InternalServerError());
                }

                return(Created(Request.RequestUri, item));
            }
            var isUpdated = await topicBL.UpdateTopic(item);

            if (isUpdated == false)
            {
                return(InternalServerError());
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
    protected void gvResult_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[3].Visible = false;

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // If option selected is the wrong answer.
            if (e.Row.Cells[2].Text.Equals("No"))
            {
                // Declare a Hyper link
                HyperLink the_url = new HyperLink();
                // Pass the related topic url to the hyperlink.
                the_url.NavigateUrl = "Topic.aspx?ID=" + e.Row.Cells[3].Text + "&lessonid=" + ViewState["lessonID"].ToString();

                TopicBL topicBL = new TopicBL();
                // Retrieve topic data.
                DataTable topic = topicBL.GetTopicByID(Convert.ToInt32(e.Row.Cells[3].Text));
                // Pass topic title to URL.
                if (topic.Rows.Count > 0)
                {
                    the_url.Text = topic.Rows[0].Field <string>("Title");
                }
                // Add URL to grid view.
                e.Row.Cells[4].Controls.Add(the_url);
            }
        }
    }
示例#3
0
        public ActionResult DeleteTopic(int ID, ref string oUTPUT)
        {
            TopicBL topicBL        = new TopicBL();
            int     recordaffected = topicBL.DeleteTopic(ID, ref oUTPUT);

            return(Json(recordaffected, JsonRequestBehavior.AllowGet));
        }
示例#4
0
    /// <summary>
    /// Bind example tables to gridviews.
    /// </summary>
    private void BindExampleTable()
    {
        // Create instance of Topic business logic.
        TopicBL topicBL = new TopicBL();

        // Get the first example table
        DataTable table = topicBL.GetExampleTable(TopicID);

        gvTableExample.DataSource = table;
        gvTableExample.DataBind();

        DataTable topic = topicBL.GetTopicByID(TopicID);

        // If the topic has a second example query, populate the second example table.
        if (topic.Rows[0].Field <string>("ExampleQuery2") != null)
        {
            DataTable table2 = topicBL.GetExampleTable2(TopicID);
            gvTableExample2.DataSource = table2;
            gvTableExample2.DataBind();
        }

        // If the topic has a third example query, populate the third example table.
        if (topic.Rows[0].Field <string>("ExampleQuery3") != null)
        {
            DataTable table3 = topicBL.GetExampleTable3(TopicID);
            gvTableExample3.DataSource = table3;
            gvTableExample3.DataBind();
        }
    }
        public async Task <IHttpActionResult> GetTopicByIdOrName(string id_or_name)
        {
            try
            {
                TopicBL topicBL = new TopicBL(_context);
                bool    isValid = Int32.TryParse(id_or_name, out int ID);
                if (isValid)
                {
                    var result = await topicBL.GetTopicById(ID);

                    if (result == null)
                    {
                        return(NotFound());
                    }
                    return(Ok(result));
                }
                else
                {
                    var name   = id_or_name;
                    var result = await topicBL.GetTopicByName(name);

                    if (result == null)
                    {
                        return(NotFound());
                    }
                    return(Ok(result));
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
示例#6
0
        //for Subject drp
        public void GetSubjectForDrp()
        {
            TopicBL topicBL = new TopicBL();
            List <TopicEntities> pocoList = new List <TopicEntities>();

            pocoList = topicBL.GetSubjectForDrp();

            List <TopicEntities> itmasterList = new List <TopicEntities>();

            foreach (TopicEntities up in pocoList)
            {
                TopicEntities unt = new TopicEntities();
                unt.ID          = up.ID;
                unt.SubjectName = up.SubjectName;

                itmasterList.Add(unt);
            }

            ViewBag.SubjectForDrp = itmasterList.Select(x =>
                                                        new SelectListItem()
            {
                Text  = x.SubjectName,
                Value = x.ID.ToString()
            });
        }
示例#7
0
    /// <summary>
    /// Binds topic title and topic description.
    /// </summary>
    /// <param name="topicID"></param>
    private void BindContent(int topicID)
    {
        TopicBL   topicBL = new TopicBL();
        DataTable table   = topicBL.GetTopicByID(topicID);

        lblLessonTitle.Text = table.Rows[0].Field <string>("Title");
        lblTopicText.Text   = table.Rows[0].Field <string>("Text");
        lblTopicText2.Text  = table.Rows[0].Field <string>("Text2");
    }
示例#8
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);
        }
    }
        public async Task <IHttpActionResult> PostTopic(Topic item)
        {
            TopicBL topicBL = new TopicBL(_context);
            var     Id      = await topicBL.CreateNewTopic(item);

            if (Id == null)
            {
                return(InternalServerError());
            }

            return(Created(String.Format("{0}/{1}", Request.RequestUri, Id), item));
        }
        public async Task <IHttpActionResult> GetTopics()
        {
            try
            {
                TopicBL topicBL = new TopicBL(_context);
                var     results = await topicBL.GetAllTopics();

                if (results.Count() == 0)
                {
                    return(Content(HttpStatusCode.OK, "No results for request"));
                }
                return(Ok(results));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
        public async Task <IHttpActionResult> DeleteTopic(int id)
        {
            TopicBL topicBL = new TopicBL(_context);

            if (!topicBL.TopicExists(id))
            {
                return(NotFound());
            }

            var result = await topicBL.DeleteTopicItem(id);

            if (result == null)
            {
                return(InternalServerError());
            }

            return(Ok(result));
        }
示例#12
0
    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);
        }
    }
示例#13
0
        public JsonResult LoadData()
        {
            int draw, start, length;
            int pageIndex = 0;

            if (null != Request.Form.GetValues("draw"))
            {
                draw   = int.Parse(Request.Form.GetValues("draw").FirstOrDefault().ToString());
                start  = int.Parse(Request.Form.GetValues("start").FirstOrDefault().ToString());
                length = int.Parse(Request.Form.GetValues("length").FirstOrDefault().ToString());
            }
            else
            {
                draw   = 1;
                start  = 0;
                length = 50;
            }

            if (start == 0)
            {
                pageIndex = 1;
            }
            else
            {
                pageIndex = (start / length) + 1;
            }

            TopicBL topicBL      = new TopicBL();
            int     totalrecords = 0;

            List <TopicEntities> topicEntities = new List <TopicEntities>();

            topicEntities = topicBL.GetTopicPageWise(pageIndex, ref totalrecords, length);

            var data = topicEntities;

            return(Json(new { draw = draw, recordsFiltered = totalrecords, recordsTotal = totalrecords, data = data }, JsonRequestBehavior.AllowGet));
        }
示例#14
0
    /// <summary>
    /// Creates links in grid view.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gvResult_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[3].Visible = false;
        e.Row.Cells[4].Visible = false;

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // If the answer of this row is wrong provide link to topic.
            if (e.Row.Cells[2].Text.Equals("No"))
            {
                HyperLink the_url = new HyperLink();
                the_url.NavigateUrl = "Topic.aspx?ID=" + e.Row.Cells[4].Text + "&lessonid=" + e.Row.Cells[3].Text;
                TopicBL   topicBL = new TopicBL();
                DataTable topic   = topicBL.GetTopicByID(Convert.ToInt32(e.Row.Cells[4].Text));
                if (topic.Rows.Count > 0)
                {
                    the_url.Text = topic.Rows[0].Field <string>("Title");
                }

                e.Row.Cells[5].Controls.Add(the_url);
            }
        }
    }
示例#15
0
    /// <summary>
    /// Called on submit button click.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string errorMessage = string.Empty;

        try
        {
            // Declare variables.
            gvResultTable.DataSource = null;
            gvResultTable.DataBind();
            lblResult.Visible = false;
            QueryBL    queryBL    = new QueryBL();
            EmployeeBL employeeBL = new EmployeeBL();
            bool       correct    = true;

            // Retrieve the correct query, execute it against the database, and return a datatable representation.
            DataTable compareTable = queryBL.GetQueryResult(TopicID);

            // If the query is an UPDATE, INSERT or DELETE query. Get the altered result.
            if (compareTable.Rows.Count == 0)
            {
                compareTable = new DataTable();
                compareTable = employeeBL.GetAllEmployee();
            }

            // Reference the user query.
            string query = txtTryItOut.Text;

            // Check if user text field contains any characters.
            if (!string.IsNullOrEmpty(txtTryItOut.Text))
            {
                query = txtTryItOut.Text.Trim();
            }
            // Inform user to type text.
            else
            {
                lblResult.Attributes.Add("class", "label label-warning");
                lblResult.Visible = true;
                // Retrieve error from XML file.
                lblResult.Text = ErrorMessage.GetErrorDesc(9).Replace("|", "<br/>");
                return;
            }

            // Recreate the table before running the user query.
            employeeBL.RecreateTable();

            // Process the user input on the table.
            DataTable resultTable = queryBL.ProcessQuery(query);

            // If the query is an UPDATE, INSERT or DELETE, retrieve the altered table.
            if (resultTable == null || resultTable.Rows.Count == 0)
            {
                resultTable = new DataTable();
                resultTable = employeeBL.GetAllEmployee();
            }

            // If table was not dropped by user query.
            if (employeeBL.IsEmployee() == 1)
            {
                // Bind to grid view.
                gvResultTable.DataSource = resultTable;
                gvResultTable.DataBind();

                // Compare no of rows and columns of database's query table to user's query table..
                if (compareTable.Rows.Count != resultTable.Rows.Count || compareTable.Columns.Count != resultTable.Columns.Count)
                {
                    correct      = false;
                    errorMessage = ErrorMessage.GetErrorDesc(4).Replace("|", "<br/>");
                }
                // If rows and columns numbers match, compare their content.
                else
                {
                    for (int i = 0; i < compareTable.Rows.Count; i++)
                    {
                        for (int j = 0; j < compareTable.Columns.Count; j++)
                        {
                            if (!(compareTable.Rows[i][j].Equals(resultTable.Rows[i][j])))
                            {
                                errorMessage = ErrorMessage.GetErrorDesc(6).Replace("|", "<br/>");;
                                correct      = false;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                // If table is dropped set correct to false, bind an empty data table to the 1st grid view.
                correct = false;
                gvResultTable.DataSource = new DataTable();
                gvResultTable.DataBind();

                // Retrieve error message from XML file.
                errorMessage = ErrorMessage.GetErrorDesc(8).Replace("|", "<br/>");;
            }

            if (correct)
            {
                errorMessage      = ErrorMessage.GetErrorDesc(5);
                lblResult.Visible = true;
                lblResult.Attributes.Add("class", "label label-success");
                lblResult.Text = errorMessage;

                userTopicBL = new UserTopicBL();

                // Set Topic completion date.
                userTopicBL.SetCompleteDate(UserID, TopicID);

                // Check if lesson is complete, by comparing complete topics with the number of topics under current lesson.
                TopicBL topicBL = new TopicBL();
                int     countTopicsUnderLesson     = topicBL.GetCountTopicsByLessonID(LessonID);
                int     countTopicsCompletedByUser = topicBL.GetCountCompletedTopics(LessonID, UserID);

                // If all lessons are complete add the lesson completion date.
                if (countTopicsCompletedByUser == countTopicsUnderLesson)
                {
                    UserLessonBL userLessonBL = new UserLessonBL();
                    userLessonBL.SetCompletionDate(UserID, LessonID);
                }
            }
            // If not correct, show the error message to the user.
            else
            {
                lblResult.Attributes.Add("class", "label label-warning");
                lblResult.Visible = true;
                lblResult.Text    = errorMessage;
            }

            // Drop table and recreate it.
            employeeBL.RecreateTable();
        }

        // This is an attempt to show different messages to the users if the submitted query gives an SQL exception.
        catch (SqlException ex)
        {
            // Error number 102 refers to bad syntax.
            if (ex.Number == 102)
            {
                errorMessage = ErrorMessage.GetErrorDesc(3).Replace("|", "<br/>");
            }
            // User tries to create a table (currently not implemeted). Since user has no permission to create en exception is thrown.
            else if (ex.Number == 262)
            {
                errorMessage = ErrorMessage.GetErrorDesc(7).Replace("|", "<br/>");
            }
            // Invalid field name.
            else if (ex.Number == 207)
            {
                errorMessage = ErrorMessage.GetErrorDesc(10).Replace("|", "<br/>");
            }
            else
            // Currently other types of exceptions show a general error.
            {
                errorMessage = ErrorMessage.GetErrorDesc(3).Replace("|", "</br>");
            }

            lblResult.Attributes.Add("class", "label label-warning");
            lblResult.Visible = true;

            lblResult.Text = errorMessage;
        }
    }
示例#16
0
        public ActionResult GetTopicByID(int ID)
        {
            TopicBL topicBL = new TopicBL();

            return(Json(topicBL.GetTopicByID(ID), JsonRequestBehavior.AllowGet));
        }
示例#17
0
        public JsonResult Add(TopicEntities topicEntities)
        {
            TopicBL topicBL = new TopicBL();

            return(Json(topicBL.SaveTopic(topicEntities), JsonRequestBehavior.AllowGet));
        }