public ActionResult EditAddress(StudentVM studentVM)
        {
            if (!ModelState.IsValid)
            {
                studentVM.Student = StudentRepository.Get(studentVM.Student.StudentId);
                studentVM.SetStateItems(StateRepository.GetAll());
                return(View(studentVM));
            }

            studentVM.Student.Address.State     = StateRepository.Get(studentVM.Student.Address.State.StateAbbreviation);
            studentVM.Student.Address.AddressId = studentVM.Student.StudentId;
            StudentRepository.SaveAddress(studentVM.Student.StudentId, studentVM.Student.Address);


            var viewModel = new StudentVM();

            viewModel.Student = StudentRepository.Get(studentVM.Student.StudentId);
            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            if (viewModel.Student.Courses != null)
            {
                viewModel.SelectedCourseIds = viewModel.Student.Courses.Select(c => c.CourseId).ToList();
            }
            return(RedirectToAction("List"));
        }
        public ActionResult EditStudent(int id)
        {
            var viewModel = new StudentVM();

            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());

            viewModel.Student = StudentRepository.Get(id);

            if (viewModel.Student.Courses == null)
            {
                viewModel.Student.Courses = new List <Course>();
            }

            foreach (Course course in viewModel.Student.Courses)
            {
                viewModel.SelectedCourseIds.Add(course.CourseId);
            }

            if (viewModel.Student.Address == null)
            {
                viewModel.Student.Address = new Address()
                {
                    AddressId = StudentRepository.GetAddressId()
                };
            }

            return(View(viewModel));
        }
Beispiel #3
0
        public ActionResult Add(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();

                foreach (var id in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(id));
                }

                if (studentVM.Student.Courses.Count == 0)
                {
                    ModelState.AddModelError("Courses", "Please select at least one course. ");
                    return(View(studentVM));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

                if (string.IsNullOrEmpty(studentVM.Student.Major.MajorName))
                {
                    ModelState.AddModelError("MajorName", "Please select a major.");
                    return(View(studentVM));
                }

                StudentRepository.Add(studentVM.Student);

                return(RedirectToAction("List"));
            }
            studentVM.SetCourseItems(CourseRepository.GetAll());
            studentVM.SetMajorItems(MajorRepository.GetAll());
            studentVM.SetStateItems(StateRepository.GetAll());
            return(View(studentVM));
        }
Beispiel #4
0
        public ActionResult Edit(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();
                foreach (var id in studentVM.CourseItems.Where(m => m.Selected))
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(int.Parse(id.Value)));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);
                StudentRepository.Edit(studentVM.Student);
                return(RedirectToAction("List"));
            }
            else
            {
                var student = StudentRepository.Get(studentVM.Student.StudentId);

                var viewModel = new StudentVM();
                viewModel.Student = student;

                viewModel.SetCourseItems(CourseRepository.GetAll());
                viewModel.SetMajorItems(MajorRepository.GetAll());
                viewModel.SetStateItems(StateRepository.GetAll());
                return(View("Edit", viewModel));
            }
        }
Beispiel #5
0
        public ActionResult EditStudent(StudentVM aStudent)
        {
            if (ModelState.IsValid)
            {
                aStudent.SelectedCourseIds =
                    aStudent.CourseItems.Where(c => c.Selected).Select(c => int.Parse(c.Value)).ToList();

                aStudent.Student.Courses = new List <Course>();

                foreach (var id in aStudent.SelectedCourseIds)
                {
                    aStudent.Student.Courses.Add(CourseRepository.Get(id));
                }

                aStudent.Student.Major         = MajorRepository.Get(aStudent.Student.Major.MajorId);
                aStudent.Student.Address.State = StateRepository.Get(aStudent.Student.Address.State.StateName);

                StudentRepository.Edit(aStudent.Student);
                StudentRepository.SaveAddress(aStudent.Student.StudentId, aStudent.Student.Address);

                return(RedirectToAction("List"));
            }
            else
            {
                var s         = StudentRepository.Get(aStudent.Student.StudentId);
                var viewModel = new StudentVM();
                viewModel.SetCourseItems(CourseRepository.GetAll());
                viewModel.SetMajorItems(MajorRepository.GetAll());
                viewModel.SetStateItems(StateRepository.GetAll());
                viewModel.Student = s;

                return(View(viewModel));
            }
        }
        public ActionResult Edit(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();

                foreach (var id in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(id));
                }

                studentVM.Student.Major         = MajorRepository.Get(studentVM.Student.Major.MajorId);
                studentVM.Student.Address.State = StateRepository.Get(studentVM.Student.Address.State.StateAbbreviation);

                StudentRepository.Edit(studentVM.Student);
                StudentRepository.SaveAddress(studentVM.Student.StudentId, studentVM.Student.Address);

                return(RedirectToAction("List"));
            }
            else
            {
                studentVM.SetCourseItems(CourseRepository.GetAll());
                studentVM.SetMajorItems(MajorRepository.GetAll());
                studentVM.SetStateItems(StateRepository.GetAll());

                return(View(studentVM));
            }
        }
Beispiel #7
0
        public ActionResult EditStudent(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                studentVM.Student.Courses = new List <Course>();

                foreach (var id in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(id));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

                StudentRepository.Edit(studentVM.Student);

                return(RedirectToAction("List"));
            }
            else
            {
                studentVM.SetCourseItems(CourseRepository.GetAll());
                studentVM.SetMajorItems(MajorRepository.GetAll());
                studentVM.SetStateItems(StateRepository.GetAll());

                if (!(studentVM.Student.Courses == null))
                {
                    studentVM.SelectedCourseIds = studentVM.Student.Courses.Select(s => s.CourseId).ToList();
                }

                return(View(studentVM));
            }
        }
Beispiel #8
0
        public ActionResult Add()
        {
            var viewModel = new StudentVM();

            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());

            viewModel.Student = new Student()
            {
                Address = new Address()
                {
                    State = new State()
                    {
                        StateAbbreviation = "",
                        StateName         = "PLACEHOLDER"
                    }
                },
                Major = new Major()
                {
                    MajorId   = -1,
                    MajorName = "PLACEHOLDER"
                }
            };
            return(View(viewModel));
        }
        public ActionResult EditStudent(int id)
        {
            var student = StudentRepository.Get(id);


            var model = new StudentVM();

            model.SetCourseItems(CourseRepository.GetAll());
            model.SetMajorItems(MajorRepository.GetAll());
            model.SetStateItems(StateRepository.GetAll());


            model.Student.FirstName = student.FirstName;
            model.Student.LastName  = student.LastName;
            model.Student.Major     = student.Major;
            model.Student.GPA       = student.GPA;
            model.Student.Courses   = student.Courses.ToList();
            model.Student.Address   = student.Address;
            model.Student.StudentId = student.StudentId;
            foreach (var studentCourse in student.Courses)
            {
                model.SelectedCourseIds.Add(studentCourse.CourseId);
            }



            return(View(model));
        }
        public ActionResult EditAddress(int studentId)
        {
            var viewModel = new StudentVM();

            viewModel.Student = StudentRepository.Get(studentId);
            viewModel.SetStateItems(StateRepository.GetAll());
            return(View(viewModel));
        }
Beispiel #11
0
        public ActionResult Edit(StudentVM studentVM)
        {
            var viewModel = new StudentVM();

            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());

            studentVM.Student.Courses = new List <Course>();

            foreach (var id in studentVM.SelectedCourseIds)
            {
                studentVM.Student.Courses.Add(CourseRepository.Get(id));
            }

            studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);

            StudentRepository.Edit(studentVM.Student);

            StudentRepository.SaveAddress(studentVM.Student.StudentId, studentVM.Student.Address);

            if (string.IsNullOrEmpty(studentVM.Student.FirstName))
            {
                ModelState.AddModelError("FistName", "Please enter the students first name.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.LastName))
            {
                ModelState.AddModelError("LastName", "Please enter the students last name.");
            }

            if (studentVM.Student.GPA > 4.0M || studentVM.Student.GPA < 0.0M)
            {
                ModelState.AddModelError("GPA", "Please enter the GPA between 0.0 and 4.0.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.Address.Street1))
            {
                ModelState.AddModelError("Student.Address.Street1", "You must provide atleast one street address.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.Address.City))
            {
                ModelState.AddModelError("Student.Address.City", "Please enter the city.");
            }

            if (string.IsNullOrEmpty(studentVM.Student.Address.PostalCode))
            {
                ModelState.AddModelError("Student.Address.PostalCode", "Please enter the postal code.");
            }

            if (ModelState.IsValid)
            {
                StudentRepository.Edit(studentVM.Student);
                return(RedirectToAction("List"));
            }
            return(View(viewModel));
        }
        public ActionResult Add()
        {
            var viewModel = new StudentVM();

            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());
            return(View(viewModel));
        }
        public IActionResult Create()
        {
            var viewModel = new StudentVM();

            viewModel.SetCourseItems(_courseRepository.GetAllCourses());
            viewModel.SetMajorItems(_majorRepository.GetAllMajors());
            viewModel.SetStateItems(_stateRepository.GetAllStates());
            return(View(viewModel));
        }
        public ActionResult EditStudent(int id)
        {
            var model = new StudentVM();

            model.SetCourseItems(CourseRepository.GetAll());
            model.SetMajorItems(MajorRepository.GetAll());
            model.SetStateItems(StateRepository.GetAll());
            model.Student = StudentRepository.Get(id);
            return(View(model));
        }
Beispiel #15
0
        public ActionResult Edit(int studentId)
        {
            var viewModel = new StudentVM();

            viewModel.Student = StudentRepository.Get(studentId);
            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());
            return(View(viewModel));
        }
Beispiel #16
0
        public ActionResult Edit(int id)
        {
            var viewModel = new StudentVM();

            viewModel.Student           = StudentRepository.Get(id);
            viewModel.SelectedCourseIds = viewModel.Student.Courses.Select(s => s.CourseId).ToList();
            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());
            return(View(viewModel));
        }
Beispiel #17
0
        public ActionResult Edit(int id)
        {
            StudentVM studentVM = new StudentVM();

            studentVM.Student = StudentRepository.Get(id);
            studentVM.SetCourseItems(CourseRepository.GetAll());
            studentVM.SetMajorItems(MajorRepository.GetAll());
            studentVM.SetStateItems(StateRepository.GetAll());

            return(View(studentVM));
        }
Beispiel #18
0
        public ActionResult Edit(int studentId)
        {
            var model           = StudentRepository.Get(studentId);
            var selectedCourses = model.Courses.Select(p => p.CourseId);
            var viewModel       = new StudentVM();

            viewModel.Student = model;
            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SelectedCourseIds = selectedCourses.ToList();
            viewModel.SetStateItems(StateRepository.GetAll());
            return(View(viewModel));
        }
        public ActionResult Delete(int studentId)
        {
            var viewModel = new StudentVM();

            viewModel.Student = StudentRepository.Get(studentId);
            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            if (viewModel.Student.Courses != null)
            {
                viewModel.SelectedCourseIds = viewModel.Student.Courses.Select(c => c.CourseId).ToList();
            }
            viewModel.SetStateItems(StateRepository.GetAll());
            return(View(viewModel));
        }
Beispiel #20
0
        public ActionResult EditStudent(int id)
        {
            var       model   = StudentRepository.Get(id);
            StudentVM student = new StudentVM();

            student.SetCourseItems(CourseRepository.GetAll());
            student.SetMajorItems(MajorRepository.GetAll());
            student.SetStateItems(StateRepository.GetAll());
            student.Student           = model;
            student.Student.Address   = model.Address;
            student.SelectedCourseIds = model.Courses.Select(m => m.CourseId).ToList();

            return(View(student));
        }
Beispiel #21
0
        public ActionResult Add(StudentVM studentVM)
        {
            if (ModelState.IsValid)
            {
                //if (studentVM.Student.GPA<0 || studentVM.Student.GPA>5)
                //{
                //    var viewModel = new StudentVM();
                //    viewModel.SetCourseItems(CourseRepository.GetAll());
                //    viewModel.SetMajorItems(MajorRepository.GetAll());
                //    viewModel.SetStateItems(StateRepository.GetAll());

                //    return View("Add", viewModel);
                //}
                //else
                //{
                studentVM.Student.Courses = new List <Course>();
                studentVM.Student.Address = new List <Address>();
                AddressVM address = new AddressVM();
                foreach (var courseID in studentVM.SelectedCourseIds)
                {
                    studentVM.Student.Courses.Add(CourseRepository.Get(courseID));
                }

                studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);
                Student modelStudent = studentVM.Student;
                //Student student = new Student();
                //student.FirstName = modelStudent.FirstName;
                //student.LastName = modelStudent.LastName;
                //student.Courses = modelStudent.Courses;
                //student.GPA = modelStudent.GPA;
                //student.Major = modelStudent.Major;
                int id2 = StudentRepository.Add(modelStudent);
                address.Student = studentVM.Student;
                //StudentRepository.SaveAddress(studentVM.Student.StudentId, studentVM.Student.Address);

                //return RedirectToAction(/*"List"*/"AddAddress", address.Student/*.StudentId*/);
                return(RedirectToAction(/*"List"*/ "AddAddress", new { id = id2 } /*.StudentId*/));
                //}
            }
            else
            {
                var viewModel = new StudentVM();
                viewModel.SetCourseItems(CourseRepository.GetAll());
                viewModel.SetMajorItems(MajorRepository.GetAll());
                viewModel.SetStateItems(StateRepository.GetAll());

                return(View("Add", viewModel));
            }
        }
Beispiel #22
0
 private StudentVM GetStudentVMListItems(StudentVM viewModel)
 {
     //Load the Selected CourseIds from Student.Courses
     if (viewModel.Student.Courses != null)
     {
         foreach (var course in viewModel.Student.Courses)
         {
             viewModel.SelectedCourseIds.Add(course.CourseId);
         }
     }
     viewModel.SetCourseItems(CourseRepository.GetAll());
     viewModel.SetMajorItems(MajorRepository.GetAll());
     viewModel.SetStateItems(StateRepository.GetAll());
     return(viewModel);
 }
Beispiel #23
0
        public ActionResult Edit(int id)
        {
            var viewModel = new StudentVM();

            viewModel.SetStateItems(StateRepository.GetAll());
            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.Student         = StudentRepository.Get(id);
            viewModel.Student.Address = StudentRepository.Get(id).Address;
            foreach (var course in StudentRepository.Get(id).Courses)
            {
                viewModel.SelectedCourseIds.Add(CourseRepository.Get(course.CourseId).CourseId);
            }
            return(View(viewModel));
        }
Beispiel #24
0
        public ActionResult EditStudent(int studentId)
        {
            var viewStudent = new StudentVM();

            viewStudent.Student = StudentRepository.Get(studentId);
            viewStudent.SetCourseItems(CourseRepository.GetAll());
            viewStudent.SetMajorItems(MajorRepository.GetAll());
            viewStudent.SetStateItems(StateRepository.GetAll());

            if (!(viewStudent.Student.Courses == null))
            {
                viewStudent.SelectedCourseIds = viewStudent.Student.Courses.Select(s => s.CourseId).ToList();
            }

            return(View(viewStudent));
        }
Beispiel #25
0
        public ActionResult Edit(int StudentId)
        {
            var student   = StudentRepository.Get(StudentId);
            var studentVM = new StudentVM();

            studentVM.Student = student;
            studentVM.SetCourseItems(CourseRepository.GetAll());
            if (studentVM.Student.Courses != null)
            {
                studentVM.SelectedCourseIds = studentVM.Student.Courses.Select(c => c.CourseId).ToList();
            }
            studentVM.SetStateItems(StateRepository.GetAll());

            studentVM.SetMajorItems(MajorRepository.GetAll());
            return(View(studentVM));
        }
Beispiel #26
0
        public ActionResult EditStudent(int id)
        {
            Student   student   = StudentRepository.Get(id);
            StudentVM viewModel = new StudentVM();

            viewModel.SetCourseItems(CourseRepository.GetAll());
            viewModel.SetMajorItems(MajorRepository.GetAll());
            viewModel.SetStateItems(StateRepository.GetAll());
            if (student.Courses != null)
            {
                foreach (Course course in student.Courses)
                {
                    viewModel.SelectedCourseIds.Add(course.CourseId);
                }
            }
            viewModel.Student = student;
            return(View(viewModel));
        }
        public ActionResult EditStudent(StudentVM viewModel)
        {
            if (ModelState.IsValid)
            {
                viewModel.Student.Major         = MajorRepository.Get(viewModel.Student.Major.MajorId);
                viewModel.Student.Address.State = StateRepository.Get(viewModel.Student.Address.State.StateAbbreviation);

                StudentRepository.Edit(viewModel.Student);
                return(RedirectToAction("List"));
            }
            else
            {
                viewModel.SetStateItems(StateRepository.GetAll());
                viewModel.SetCourseItems(CourseRepository.GetAll());
                viewModel.SetMajorItems(MajorRepository.GetAll());
                return(View(viewModel));
            }
        }
        public ActionResult EditStudent(int id)
        {
            var studentVM = new StudentVM();

            studentVM.SetCourseItems(CourseRepository.GetAll());
            studentVM.SetMajorItems(MajorRepository.GetAll());
            studentVM.SetStateItems(StateRepository.GetAll());
            studentVM.Student = StudentRepository.Get(id);

            if (studentVM.Student.Courses != null)
            {
                foreach (Course course in studentVM.Student.Courses)
                {
                    studentVM.SelectedCourseIds.Add(course.CourseId);
                }
            }

            return(View(studentVM));
        }
Beispiel #29
0
        public ActionResult EditStudent(int StudentId)
        {
            var student = StudentRepository.Get(StudentId);

            var model = new StudentVM();

            model.SetCourseItems(CourseRepository.GetAll());
            model.SetMajorItems(MajorRepository.GetAll());
            model.SetStateItems(StateRepository.GetAll());

            if (student.Courses != null)
            {
                foreach (var course in student.Courses)
                {
                    model.SelectedCourseIds.Add(course.CourseId);
                }
            }
            model.Student = student;
            return(View(model));
        }
Beispiel #30
0
        public ActionResult Edit(StudentVM studentVM)
        {
            {
                if (ModelState.IsValid)
                {
                    var selectedCourses = studentVM.CoursesCheckBoxes.Where(c => c.IsSelected).Select(c => c.Course.CourseId);
                    studentVM.Student.Courses = new List <Course>();
                    foreach (var course in selectedCourses)
                    {
                        studentVM.Student.Courses.Add(CourseRepository.Get(course));
                    }
                    studentVM.Student.Major = MajorRepository.Get(studentVM.Student.Major.MajorId);
                    //studentVM.Student.GPA = StudentRepository.
                    StudentRepository.SaveAddress(studentVM.Student.StudentId, studentVM.Student.Address);
                    StudentRepository.Edit(studentVM.Student);
                    return(RedirectToAction("List"));
                }
                else
                {
                    var student = StudentRepository.Get(studentVM.Student.StudentId);

                    studentVM.SetCourseItems(CourseRepository.GetAll());
                    studentVM.SetMajorItems(MajorRepository.GetAll());
                    studentVM.SetStateItems(StateRepository.GetAll());
                    studentVM.Student.StudentId = student.StudentId;
                    studentVM.Student.FirstName = student.FirstName;
                    studentVM.Student.LastName  = student.LastName;
                    studentVM.Student.GPA       = student.GPA;
                    studentVM.Student.Major     = student.Major;
                    studentVM.Student.Courses   = student.Courses;
                    studentVM.Student.Address   = student.Address;
                    studentVM.CoursesCheckBoxes = (from course in CourseRepository.GetAll()
                                                   select new CoursesCheckBoxItem {
                        Course = course, IsSelected = student.Courses.Any(c => c.CourseId == course.CourseId)
                    }).ToList();

                    return(View(studentVM));
                }
            }
        }