Пример #1
0
        public void AddAssignment()
        {
            //Q: can we add an assignment?

            //prep
            var _context       = new MackTechGroupProject.Models.ApplicationDbContext();
            int courseId       = 34;
            var selectedCourse = _context.Courses.Where(x => x.CourseId == courseId).FirstOrDefault();
            //Guid assignmentGuid = Guid.NewGuid();

            var assignment = new Assignment
            {
                Course                = selectedCourse,
                Points                = 100,
                AssignmentTitle       = "Unit Test",
                AssignmentDescription = "Unit Test added course",
                DueDate               = DateTime.Now,
                SubmissionType        = "Text-Submission",
                AssignmentAddedOn     = DateTime.Now
            };

            //perform operations
            Boolean result = AssignmentService.AddAssignmentService(courseId, assignment, _context);

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

            var y = _context.Assignments.Where(x => x.AssignmentId == assignment.AssignmentId);

            System.Diagnostics.Debug.WriteLine(y.Count());
            Assert.IsTrue(y.Count() == 1);
        }
Пример #2
0
        public ActionResult AddAssignment(int id, Assignment model)
        {
            if (ModelState.IsValid)
            {
                var selectedCourseId = id;
                var Assignment       = new Assignment();
                var context          = HttpContext.GetOwinContext().Get <ApplicationDbContext>();
                var selectedCourse   = context.Courses.Where(x => x.CourseId == selectedCourseId).FirstOrDefault();

                var assignment = new Assignment
                {
                    AssignmentId          = model.AssignmentId,
                    Course                = selectedCourse,
                    Points                = model.Points,
                    AssignmentTitle       = model.AssignmentTitle,
                    AssignmentDescription = model.AssignmentDescription,
                    DueDate               = model.DueDate.AddHours(23).AddMinutes(59),
                    SubmissionType        = model.SubmissionType,
                    AssignmentAddedOn     = DateTime.Now
                };

                Boolean result = AssignmentService.AddAssignmentService(selectedCourseId, assignment, context);

                if (result)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }