示例#1
0
        /// <summary>
        /// Calculates aggregated progress data for all sets in the specified class.
        /// If a non-null user is passed in, then the data is limited to that student's progress.
        /// If a non-null set is passed in, then the data is limited to problems in that set.
        /// </summary>
        /// <param name="cls">The ClassData object with the class's id</param>
        /// <param name="user">The UserData object with the user's id (optional)</param>
        /// <param name="set">The ProblemSetData object with the set's id (optional)</param>
        /// <returns>A non-null, possibly empty list of ProblemProgress objects</returns>
        public List<ProblemProgress> GetProblemProgress(ClassData cls, UserData user = null, ProblemSetData set = null)
        {
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                List<ProblemProgress> list = new List<ProblemProgress>();
                SqlCommand cmd = conn.CreateCommand();

                string selectCols = "probs.Id, probs.Name";

                StringBuilder query = new StringBuilder();
                query.AppendLine("Select " + selectCols + ", ");
                query.AppendLine("  Count(Case probs.IsCorrect When 1 Then 1 Else null End) as NumCorrect, ");
                query.AppendLine("  Avg(Cast(probs.NumAttempts as float)) as AvgAttempts ");
                query.AppendLine("from ( ");
                query.AppendLine("  Select distinct p.*, s.IsCorrect, IsNull(s.NumAttempts, 0) as NumAttempts ");
                query.AppendLine("  from dbo.[Problem] p ");
                query.AppendLine("  Left Join dbo.[Solution] s on s.ProblemId = p.Id ");
                query.AppendLine("  Join dbo.[ProblemSetProblem] psp on psp.ProblemId = p.Id ");
                query.AppendLine("  Where p.ClassId = @clsId ");
                if (user != null)
                {
                    query.AppendLine("  and (s.UserId = @userId or s.UserId is null) ");
                    cmd.Parameters.AddWithValue("@userId", user.Id);
                }
                if (set != null)
                {
                    query.AppendLine("  and psp.ProblemSetId = @setId ");
                    cmd.Parameters.AddWithValue("@setId", set.Id);
                }
                query.AppendLine(") probs ");
                query.AppendLine("Group by " + selectCols);

                //Class
                cmd.Parameters.AddWithValue("@clsId", cls.Id);

                cmd.CommandText = query.ToString();

                SqlDataReader reader = null;
                try
                {
                    conn.Open();
                    reader = cmd.ExecuteReader();

                    if (reader.HasRows)
                        while (reader.Read())
                            list.Add(createProblemProgressFromReader(reader));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
                finally
                {
                    if (reader != null)
                        reader.Close();
                }

                return list;
            }
        }
示例#2
0
        public void TestAddStudent()
        {
            ClassData cls = new ClassData(1);
            UserData user = new UserData(8);

            //This user should already be a student in the class
            Assert.IsFalse(userModel.AddStudent(user, cls));
        }
示例#3
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string confirmationToken = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, null, true);

                    UserData user = new UserData(WebSecurity.GetUserId(model.UserName));
                    user.Email = model.UserName;
                    user.FirstName = model.FirstName;
                    user.LastName = model.LastName;
                    GlobalStaticVars.StaticCore.AddUser(user);

                    dynamic email = new Email("RegisterEmail");
                    email.To = model.UserName;
                    email.Name = model.FirstName ?? model.UserName;
                    email.ConfirmationToken = confirmationToken;
                    email.Send();

                    return RedirectToAction("RegisterStepTwo");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
示例#4
0
 public bool AddUser(UserData user)
 {
     return userModel.Add(user);
 }
示例#5
0
 /// <summary>
 /// Calculates aggregated progress data for all sets in the specified class.
 /// If a non-null user is passed in, then the data is limited to that student's progress.
 /// </summary>
 /// <param name="cls">The ClassData object with the class's id</param>
 /// <param name="user">The UserData object with the user's id (optional)</param>
 /// <returns></returns>
 public List<SetProgress> GetSetProgress(ClassData cls, UserData user = null)
 {
     return progressDao.GetSetProgress(cls, user);
 }
示例#6
0
 /// <summary>
 /// Calculates aggregated progress data for all sets in the specified class.
 /// If a non-null user is passed in, then the data is limited to that student's progress.
 /// If a non-null set is passed in, then the data is limited to problems in that set.
 /// </summary>
 /// <param name="cls">The ClassData object with the class's id</param>
 /// <param name="user">The UserData object with the user's id (optional)</param>
 /// <param name="set">The ProblemSetData object with the set's id (optional)</param>
 /// <returns>A non-null, possibly empty list of ProblemProgress objects</returns>
 public List<ProblemProgress> GetProblemProgress(ClassData cls, UserData user = null, ProblemSetData set = null)
 {
     return progressDao.GetProblemProgress(cls, user, set);
 }