Esempio n. 1
0
        // GET: Courses
        public ActionResult Index()
        {
            if (User.IsInRole("CanManageWebsite"))
            {
                CoursesViewModel CoursesViewModel = new CoursesViewModel()
                {
                    Courses = _context.Courses.Include("Category").OrderBy(c => c.GradeLevel).ToList(),
                    Classes = _context.Classes.ToList()
                };
                return(View(CoursesViewModel));
            }

            List <Course> availableCourses = _context.Courses.ToList();
            string        Id      = User.Identity.GetUserId();
            Student       student = _context.Students.Include("CourseRequests").Include("Classes").SingleOrDefault(s => s.UserId == Id);

            StudentCoursesViewModel model = new StudentCoursesViewModel()
            {
                student          = student,
                CanSelectCourses = _context.StudentsCanPickCourses,
                Requests         = student.CourseRequests
            };

            return(View("StudentCourses", model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Post(StudentCoursesViewModel studentCoursesViewModel)
        {
            using (var logger = _loggerManager.CreateLogger())
            {
                try
                {
                    if (!ModelState.IsValid)
                    {
                        return(BadRequest());
                    }

                    foreach (var courseDegree in studentCoursesViewModel.CoursesDegrees)
                    {
                        await _studentCourseService.Create(new StudentCourseDto
                        {
                            StudId = studentCoursesViewModel.StudentId,
                            CrsId  = courseDegree.CourseId,
                            Degree = courseDegree.Degree
                        });
                    }
                    logger.LogInformation($"All degrees for student {studentCoursesViewModel.StudentId} is added.");
                    return(Ok());
                }
                catch (Exception ex)
                {
                    logger.LogError("Something happend while adding studentCrs", ex);
                    return(StatusCode(500));
                }
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Get(int studentId)
        {
            using (var logger = _loggerManager.CreateLogger())
            {
                try
                {
                    var studentCrs = await _studentCourseService.FindByCondition(d => d.StudId == studentId);

                    var studentCrsModel = new StudentCoursesViewModel();
                    studentCrsModel.StudentId = studentId;
                    foreach (var item in studentCrs)
                    {
                        studentCrsModel.CoursesDegrees.Add(new CoursesDegree {
                            Id = item.Id, CourseId = item.CrsId, Degree = item.Degree
                        });
                    }

                    if (studentCrsModel.CoursesDegrees.Any())
                    {
                        logger.LogInformation($"studentCrs of {studentId} is retreived");
                        return(Ok(studentCrsModel));
                    }

                    return(NoContent());
                }
                catch (Exception ex)
                {
                    logger.LogError("Something happend while getting studentCrs", ex);
                    return(StatusCode(500));
                }
            }
        }
Esempio n. 4
0
        // GET: Registry
        public async Task <IActionResult> Index(string studentsCourse, string searchString)
        {
            IQueryable <string> courseQuery = from s in _context.Student
                                              orderby s.Course
                                              select s.Course;

            var students = from s in _context.Student
                           select s;

            if (!String.IsNullOrEmpty(searchString))
            {
                students = students.Where(s => s.Name.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(studentsCourse))
            {
                students = students.Where(s => s.Course == studentsCourse);
            }

            var studentsCourseVm = new StudentCoursesViewModel
            {
                Courses  = new SelectList(await courseQuery.Distinct().ToListAsync()),
                Students = await students.ToListAsync()
            };

            return(View(studentsCourseVm));
        }
Esempio n. 5
0
        public ActionResult UnEnroll()
        {
            var model = new StudentCoursesViewModel();

            ViewBag.Students = db.Students.ToList();
            ViewBag.Courses  = db.Courses.ToList();
            return(View(model));
        }
 public void AddCourseToStudent(StudentCoursesViewModel studentCoursesViewModel)
 {
     unitOfWork.StudentCourse.Add(new StudentCourse
     {
         StudentId          = studentCoursesViewModel.StudentId,
         CourseId           = studentCoursesViewModel.CourseId,
         Attestation_first  = studentCoursesViewModel.Attestation_first,
         Attestation_second = studentCoursesViewModel.Attestation_second,
         Exam = studentCoursesViewModel.Exam
     });
 }
Esempio n. 7
0
        public ActionResult Enroll(StudentCoursesViewModel model)
        {
            var student = db.Students.Find(model.StudentId);
            var course  = db.Courses.Find(model.CourseId);

            if (student != null && course != null)
            {
                student.Courses = new List <Course>();
                student.Courses.Add(course);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = student.Id }));
            }
            return(View());
        }
Esempio n. 8
0
        public ActionResult UnEnroll(StudentCoursesViewModel model)
        {
            var student = db.Students.Include(s => s.Courses).FirstOrDefault(s => s.Id == model.StudentId);
            var course  = db.Courses.Find(model.CourseId);

            if (student != null)
            {
                if (!student.Courses.Contains(course))
                {
                    return(RedirectToAction("Index"));
                }
                student.Courses.Remove(course);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = student.Id }));
            }
            return(View());
        }
Esempio n. 9
0
        public ActionResult UnEnroll(StudentCoursesViewModel model)
        {
            var student = db.Students.Include(s => s.Courses).FirstOrDefault(s => s.Id == model.StudentId);

            var course = db.Courses.Find(model.CourseId);

            if (student != null && course != null)
            {
                if (!student.Courses.Exists(c => c.Id == course.Id))                 // Если элемента нет, но его пытаются удалить
                {
                    return(RedirectToAction("Details", new { id = student.Id }));
                }

                student.Courses.Remove(course);
                db.SaveChanges();
                return(RedirectToAction("Details", new { id = student.Id }));
            }

            return(View());
        }
Esempio n. 10
0
 public StatusCodeResult CreateNewRentals(StudentCoursesViewModel enrollCourses)
 {
     //var student = _context.Students.Single(
     //     c => c.Id.Equals(enrollCourses.StudentId));
     //if (student == null)
     //    return BadRequest();
     //CourseStudent cs = new CourseStudent();
     //var courses = _context.Courses.Where(
     //    m => enrollCourses.CoursesIds.Contains(m.CourseId)).ToList();
     //foreach (var course in courses)
     //{
     //    if (course != null)
     //    {
     //        cs.Course = course;
     //        cs.CourseId = course.CourseId;
     //        cs.Student = student;
     //        cs.StudentId = Convert.ToString(student.Id);
     //        _context.SaveChanges();
     //    }
     //}
     return(Ok());
 }