public async Task <OperationResult> AppointCourseToStudent(StudentsForDisplay model)
        {
            var result = new OperationResult();

            try
            {
                var studentsCourses = _uow.GetRepository <CourseUser>().Where(x => x.UserId == model.Id);
                _uow.GetRepository <CourseUser>().Remove(studentsCourses);
                if (model.Courses != null)
                {
                    foreach (var courseId in model.Courses)
                    {
                        _uow.GetRepository <CourseUser>().Add(new CourseUser
                        {
                            UserId   = model.Id,
                            CourseId = courseId
                        });
                    }
                }

                await _uow.CommitAsync();

                result.Succeeded = true;
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AppointSubject(StudentsForDisplay model)
        {
            StudentCourses studentCourses;

            if (!ModelState.IsValid)
            {
                studentCourses = await _courseService.GetCourseToStudentAsync(model.Id);

                ViewBag.Courses = studentCourses.Courses.Select(x => new SelectListItem(x.Value, x.Key.ToString(), studentCourses.CurrentCourseIds.Contains(x.Key)));
                return(View(model));
            }

            var result = await _courseService.AppointCourseToStudent(model);

            if (result.Succeeded)
            {
                return(RedirectToAction("GetListOfStudents", "ApplicationUser"));
            }

            studentCourses = await _courseService.GetCourseToStudentAsync(model.Id);

            ViewBag.Courses = studentCourses.Courses.Select(x => new SelectListItem(x.Value, x.Key.ToString(), studentCourses.CurrentCourseIds.Contains(x.Key)));

            return(View(model));
        }