public IActionResult Add(string courseName, string semesterId)
        {
            var user = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _context);

            if (user != null)
            {
                var schedule = user.Schedules.Where(s => s.ScheduleId.Equals(semesterId)).First();

                var course = _context.Courses.Where(c => c.Name.Equals(courseName)).FirstOrDefault();
                if (course != null)
                {
                    schedule.Courses.Add(course);
                }

                if (!_service.ValidateSchedule(user.UserId, user.Schedules.ToList(), out string Errormessage))
                {
                    ViewData["ErrorMessage"] = "Cannot add " + course.Name + " because " + Errormessage;
                    schedule.Courses.Remove(course);
                }
                _context.Update(user);
                _context.SaveChanges();
                List <Degree> remainingRequirements = _service.GetRemainingRequirements(user.UserId, out string message);
                var           remainingCourses      = RemainingCourses(remainingRequirements);

                ViewData["Schedules"] = _context.Users.Find(User.Identity.Name).Schedules;
                ViewData["Courses"]   = remainingCourses;
            }
            return(View("Schedules"));
        }
        // GET: Schedule/FillRemainingRequirements/
        public IActionResult FillRemainingRequirements()
        {
            userId = User.Identity.Name;
            User user = ControllerHelpers.GetOrCreateUser(userId, _context);

            if (user == null)
            {
                ViewData["Message"] = "You must login to use this feature";
                return(View("NullUser"));
            }
            List <Degree> remainingCourses = _service.GetRemainingRequirements(userId, out string message);

            try
            {
                ViewData["Remaining"] = _service.AdjustRemainingRequirements(remainingCourses, user.Schedules.ToList());
            }
            catch (NullReferenceException e)
            {
                if (remainingCourses != null)
                {
                    ViewData["Remaining"] = remainingCourses;
                }
            }
            return(View("FillRemainingRequirements"));
        }
Exemple #3
0
        //GET: Profile
        public async Task <IActionResult> Index()
        {
            var user = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _context);

            if (user == null)
            {
                return(NotFound());
            }
            ViewData["PossibleDegrees"] = _reqContext.Degrees.ToList();
            ViewData["MyDegrees"]       = GetMyDegrees(user.Major);
            return(View(user));
        }
Exemple #4
0
        public IActionResult RemoveDegree(string degreeId)
        {
            var user = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _context);

            if (user != null)
            {
                _service.RemoveDegreeFromUser(user.UserId, degreeId);
                ViewData["Major"]           = GetDegrees(user.Major);
                ViewData["MyDegrees"]       = GetMyDegrees(user.Major);
                ViewData["PossibleDegrees"] = _reqContext.Degrees.ToList();
            }
            return(View("Index", user));
        }
        // GET: CompletedCourses
        public IActionResult CompletedCourses()
        {
            userId = User.Identity.Name;
            User user = ControllerHelpers.GetOrCreateUser(userId, _context);

            if (user == null)
            {
                ViewData["Message"] = "You must login to use this feature";
                return(View("NullUser"));
            }
            ViewData["Courses"] = user.CompletedCourses;
            return(View("CompletedCourses"));
        }
Exemple #6
0
 public IActionResult Index()
 {
     if (ControllerHelpers.IsAdmin(User.Identity.Name, _usersContext))
     {
         IList <Degree> degrees = _requirementsContext
                                  .Degrees
                                  .Select(d => d)
                                  .ToList();
         return(View(degrees));
     }
     else
     {
         return(View("NotAdmin"));
     }
 }
Exemple #7
0
        public IActionResult Update(string name, int year)
        {
            var user = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _context);

            if (user != null)
            {
                user.Name = name;
                user.Year = year;
                _context.Update(user);
                _context.SaveChanges();
                ViewData["Major"]           = GetDegrees(user.Major);
                ViewData["MyDegrees"]       = GetMyDegrees(user.Major);
                ViewData["PossibleDegrees"] = _reqContext.Degrees.ToList();
            }
            return(View("Index", user));
        }
        public IActionResult Complete(string scheduleId)
        {
            var user = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _context);

            if (user == null)
            {
                return(new NotFoundResult());
            }
            _service.AddCoursesFromSchedule(user.UserId, scheduleId);
            List <Degree> remainingRequirements = _service.GetRemainingRequirements(user.UserId, out string message);
            var           remainingCourses      = RemainingCourses(remainingRequirements);

            ViewData["Schedules"] = _context.Users.Find(User.Identity.Name).Schedules;
            ViewData["Courses"]   = remainingCourses;
            return(View("Schedules"));
        }
        public IActionResult Add(string CourseId)
        {
            var course = _contexts.Courses.Find(CourseId);
            var user   = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _contexts);

            if (user != null)
            {
                user.CompletedCourses.Add(course);
                _contexts.Update(user);
                _contexts.SaveChanges();
                return(View("Index", _contexts.Courses.ToList()));
            }
            else
            {
                return(View("NullUser"));
            }
        }
        // GET: Schedules
        public IActionResult Schedules()
        {
            userId = User.Identity.Name;
            User user = ControllerHelpers.GetOrCreateUser(userId, _context);

            if (user == null)
            {
                ViewData["Message"] = "You must login to use this feature";
                return(View("NullUser"));
            }
            List <Degree> remainingRequirements = _service.GetRemainingRequirements(userId, out string message);
            var           remainingCourses      = RemainingCourses(remainingRequirements);

            ViewData["ErrorMessage"] = "";
            ViewData["Schedules"]    = user.Schedules;
            ViewData["Courses"]      = remainingCourses;
            return(View("Schedules"));
        }
        public IActionResult New(string semesterId)
        {
            var user = ControllerHelpers.GetOrCreateUser(User.Identity.Name, _context);

            if (user == null)
            {
                return(new NotFoundResult());
            }
            var scheduleId  = semesterId + user.UserId;
            var newSchedule = new Schedule()
            {
                Semester   = semesterId,
                ScheduleId = semesterId,
                Courses    = new List <Models.Users.Entities.Course>()
            };

            _service.AddScheduleToUser(user.UserId, newSchedule);
            List <Degree> remainingRequirements = _service.GetRemainingRequirements(user.UserId, out string message);
            var           remainingCourses      = RemainingCourses(remainingRequirements);

            ViewData["Schedules"] = _context.Users.Find(User.Identity.Name).Schedules;
            ViewData["Courses"]   = remainingCourses;
            return(View("Schedules"));
        }