コード例 #1
0
        public ProgressAndAssessmentViewModel FetchProgressResults(String uname)
        {
            ProgressAndAssessmentViewModel paavm = new ProgressAndAssessmentViewModel
            {
                CompletedLessons = new List <string>(),
                AssessmentScores = new Dictionary <String, Int16>()
            };

            using (MySqlConnection conn = GetConnection())
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(
                    "SELECT s.sectionName as Lesson "
                    + "FROM `User` u "
                    + "INNER JOIN `Completion` c ON u.userId = c.userId "
                    + "INNER JOIN `Section` s ON s.sectionId = c.sectionId "
                    + "WHERE u.username = '******' "
                    + "ORDER BY u.username;", conn);
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        paavm.CompletedLessons.Add(reader.GetString("Lesson"));
                    }
                }
            }
            using (MySqlConnection conn = GetConnection())
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand(
                    "SELECT g.score as Score, s.sectionName as Assessment "
                    + "FROM `User` u "
                    + "INNER JOIN `Grade` g ON u.userId = g.userId "
                    + "INNER JOIN `Section` s ON s.sectionId = g.sectionId "
                    + "WHERE u.username = '******' "
                    + "ORDER BY u.username;", conn);
                using (MySqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        try
                        {
                            paavm.AssessmentScores.Add(reader.GetString("Assessment"), reader.GetInt16("Score"));
                        }
                        catch (Exception)
                        {
                            //this means there's a duplicate entry. just go to next.
                        }
                    }
                }
            }

            return(paavm);
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: iarslan/CodePyramid
        public ActionResult MyAccount()
        {
            String uname = Request.Cookies["currentUser"];

            if (uname == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            CodePyramidContext             context = HttpContext.RequestServices.GetService(typeof(CodePyramidContext)) as CodePyramidContext;
            ProgressAndAssessmentViewModel paavm   = context.FetchProgressResults(uname);

            paavm.CompletedLessons.Sort();
            return(View(paavm));
        }