public ActionResult AddCourse(Course course)
        {
            if (ModelState.IsValid)
            {
                course.UserId = User.Identity.GetUserId();
                _teacherRepository.CreateCourse(course);
                return RedirectToAction("EditCourse", new { id = course.ClassId });
            }

            return View(course);
        }
        public void EditCourse(Course course)
        {
            using (SqlConnection cn = new SqlConnection(Config.GetConnectionString()))
            {
                var p = new DynamicParameters();
                p.Add("@UserId", course.UserId);
                p.Add("@Name", course.Name);
                p.Add("@GradeLevel", course.GradeLevel);
                p.Add("@Subject", course.Subject);
                p.Add("@StartDate", course.StartDate);
                p.Add("@EndDate", course.EndDate);
                p.Add("@IsArchived", course.IsArchived);
                p.Add("@Description", course.Description);
                p.Add("@ClassId", course.ClassId);

                cn.Execute("ClassUpdate", p, commandType: CommandType.StoredProcedure);
            }
        }
        public void CreateClassTest()
        {
            TeacherRepository repo = new TeacherRepository();
            var newCourse = new Course
            {
                UserId = "6d8bfd69-9321-4847-9633-5d7214c97f68",
                Description = "Unit Tested Class",
                StartDate = new DateTime(2014, 6, 15),
                EndDate = new DateTime(2014, 9, 15),
                GradeLevel = 5,
                IsArchived = false,
                Name = "Unit testing 101",
                Subject = "Programming"
            };

            repo.CreateCourse(newCourse);

            Assert.AreNotEqual(0, newCourse.ClassId);
        }
        public void CreateCourse(Course course)
        {
            using (SqlConnection cn = new SqlConnection(Config.GetConnectionString()))
            {
                var p = new DynamicParameters();
                p.Add("@UserId", course.UserId);
                p.Add("@Name", course.Name);
                p.Add("@GradeLevel", course.GradeLevel);
                p.Add("@Subject", course.Subject);
                p.Add("@StartDate", course.StartDate);
                p.Add("@EndDate", course.EndDate);
                p.Add("@Description", course.Description);
                p.Add("@ClassId", dbType: DbType.Int32, direction: ParameterDirection.Output);

                cn.Execute("ClassInsert", p, commandType: CommandType.StoredProcedure);

                course.ClassId = p.Get<int>("@ClassId");
            }
        }
        public ActionResult EditAssignment(AssignmentView assignmentView)
        {
            _gradeBookRepository.EditAssignment(assignmentView.NewAssignment);
            int classId = 0;
            var gradeBook = new GradeBook();
            var course = new Course();
            classId=_gradeBookRepository.GetAssignment(assignmentView.NewAssignment.AssignmentId).ClassId;

            course = _teacherRepository.GetCourseById(classId);
            gradeBook.Course = course;
            gradeBook.AssignmentList = _gradeBookRepository.GetListOfAssignmentsById(classId);

            return View("GradeBookDisplay", gradeBook);
        }
        // ado example
        public Course GetCourseById(int id)
        {
            Course course = null;

            using (var cn = new SqlConnection(Config.GetConnectionString()))
            {
                var cmd = new SqlCommand("ClassGetById", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@ClassId", id);

                cn.Open();

                using (var dr = cmd.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        course = new Course()
                        {
                            ClassId = (int)dr["ClassId"],
                            UserId = dr["UserId"].ToString(),
                            Name = dr["Name"].ToString(),
                            GradeLevel = (byte)dr["GradeLevel"],
                            IsArchived = (bool)dr["IsArchived"],
                            Subject = dr["Subject"].ToString(),
                            StartDate = (DateTime)dr["StartDate"],
                            EndDate = (DateTime)dr["EndDate"],
                            Description = dr["Description"].ToString()
                        };
                    }
                }
            }

            return course;
        }
 public ActionResult UpdateCourseInfo(Course course)
 {
     var courseInfo = new DisplayCourseInfoModels ();
     _teacherRepository.EditCourse(course);
      course = _teacherRepository.GetCourseById(course.ClassId);
     courseInfo.Course = course;
     courseInfo.ClassId = course.ClassId;
        // courseInfo.Course.EndDate = course.EndDate;
     var gradeList = _teacherRepository.GetCumulativeGradesList(course.ClassId);
     courseInfo.StudentGrades = gradeList;
     return View("DisplayCourseInfo", courseInfo);
 }
        public ActionResult EditCourse(Course course)
        {
            if (ModelState.IsValid)
            {
                _teacherRepository.EditCourse(course);
                course = _teacherRepository.GetCourseById(course.ClassId);
                ViewBag.Message = "Course created!";
            }

            return View("EditCourse", course);
        }