Beispiel #1
0
        public void RegisterThirdCourse() //uses [email protected]
        {
            //Q: can we add a course to existing enrollments

            //prep
            var _context           = new MackTechGroupProject.Models.ApplicationDbContext();
            var sUserEmail         = "*****@*****.**";
            var sUserId            = "2eb4cb27-3c69-4bd5-9eb0-eb0dd4991a7f";
            int courseId           = 34;
            var currentEnrollments = _context.Enrollments.Where(x => x.User.Email == sUserEmail).Include(x => x.User).Include(x => x.Course).ToList();

            //perform operations
            Boolean result = RegistrationService.AddCourseService(sUserId, courseId, currentEnrollments, _context);

            //verify and interpret results
            Assert.IsTrue(result);

            var y = _context.Enrollments.Where(x => x.User.Email == sUserEmail);

            System.Diagnostics.Debug.WriteLine(y.Count());
            Assert.IsTrue(y.Count() == 3);
        }
        public ActionResult RegisterForCourse(int id)
        {
            if (ModelState.IsValid)
            {
                String userId           = User.Identity.GetUserId();
                var    selectedCourseId = id;
                var    context          = HttpContext.GetOwinContext().Get <ApplicationDbContext>();

                Boolean result = RegistrationService.AddCourseService(userId, selectedCourseId, currentEnrollments, context);

                if (result)
                {
                    return(RedirectToAction("StudentAccount", "Courses"));
                }
                else
                {
                    TempData["ErrorMessage"] = "Error: You are already registered for this course";
                    return(RedirectToAction("CourseRegistration", "Courses"));
                }
            }

            //don't want to get this far
            return(RedirectToAction("CourseRegistration", "Courses"));
        }