public ActionResult AddAssignment(AddAssignmentVM vm)
        {
            if (vm.DueDate > vm.CourseDetails.EndDate || vm.DueDate < vm.CourseDetails.StartDate)
            {
                ModelState.AddModelError("DateRange", "The due date must be between the start date and end date of the course.");
            }

            if (!ModelState.IsValid)
            {
                var courseResponse = _courseManager.GetCourseDetailsById(vm.CourseId);
                if (courseResponse.Success)
                {
                    vm.CourseDetails = courseResponse.Data;
                    return View(vm);
                }
                else
                {
                    ViewBag.ErrorMsg = courseResponse.Message;
                    return View("Error");
                }
            }

            var newAssignment = new Assignment()
            {
                AssignmentDescription = vm.AssignmentDescription,
                AssignmentName = vm.AssignmentName,
                CourseId = vm.CourseId,
                DueDate = vm.DueDate,
                PossiblePoints = vm.PossiblePoints
            };

            var response = _assignmentManager.AddAssignment(newAssignment);
            if (response.Success)
            {
                return RedirectToAction("Gradebook", new { id = newAssignment.CourseId });
            }
            else
            {
                ViewBag.ErrorMsg = response.Message;
                return View("Error");
            }
        }
 public ActionResult AddAssignment(int id)
 {
     var courseId = id;
     var courseResponse = _courseManager.GetCourseDetailsById(courseId);
     if (courseResponse.Success)
     {
         var vm = new AddAssignmentVM()
         {
             CourseDetails = courseResponse.Data,
             CourseId = courseResponse.Data.CourseId,
             DueDate = DateTime.Today
         };
         return View(vm);
     }
     else
     {
         ViewBag.ErrorMsg = courseResponse.Message;
         return View("Error");
     }
 }
        public ActionResult AssignmentInformation(AddAssignmentVM vm)
        {
            if (!ModelState.IsValid)
            {

                var courseResponse = _courseManager.GetCourseDetailsById(vm.CourseId);

                if (courseResponse.Success)
                {
                    vm.CourseDetails = courseResponse.Data;
                    return View(vm);
                }
                else
                {
                    ViewBag.ErrorMsg = courseResponse.Message;
                    return View("Error");
                }
            }

            var deleteResponse = _assignmentManager.DeleteAssignment(vm.AssignmentId, _assignmentManager.GetGradebook(vm.CourseId).GradebookListItems);

            if (!deleteResponse.Success)
            {
                ViewBag.ErrorMsg = deleteResponse.Message;
                return View("Error");
            }

            var newAssignment = new Assignment()
            {
                AssignmentDescription = vm.AssignmentDescription,
                AssignmentName = vm.AssignmentName,
                CourseId = vm.CourseId,
                DueDate = vm.DueDate,
                PossiblePoints = vm.PossiblePoints
            };

            var response = _assignmentManager.AddAssignment(newAssignment);
            if (response.Success)
            {
                return RedirectToAction("Gradebook", new { id = newAssignment.CourseId });
            }
            else
            {
                ViewBag.ErrorMsg = response.Message;
                return View("Error");
            }
        }
        public ActionResult AssignmentInformation(int Id, int assignmentId)
        {
            var courseId = Id;
            var assignmentResponse = _assignmentManager.GetAssignmentById(assignmentId);
            var courseResponse = _courseManager.GetCourseDetailsById(courseId);

            if (courseResponse.Success && assignmentResponse.Success)
            {
                var assignmentDetails = assignmentResponse.Data;

                var vm = new AddAssignmentVM()
                {
                    AssignmentId = assignmentId,
                    CourseDetails = courseResponse.Data,
                    CourseId = courseResponse.Data.CourseId,
                    AssignmentName = assignmentDetails.AssignmentName,
                    PossiblePoints =  assignmentDetails.PossiblePoints,
                    AssignmentDescription = assignmentDetails.AssignmentDescription,
                    DueDate = assignmentDetails.DueDate
                };
                return View(vm);
            }
            else
            {
                ViewBag.ErrorMsg = courseResponse.Message + assignmentResponse.Message;
                return View("Error");
            }
        }