Exemplo n.º 1
0
        /// <returns>Returns not started courses of student.</returns>
        public ActionResult NotStartedCourses()
        {
            Domain.Core.Student user = _studentRepository.GetWithCourses(User.Identity.Name);
            if (user != null)
            {
                var courses = user.Courses.Where(course => course.StartDate.CompareTo(DateTime.Now) == 1).ToList();
                if (courses.Count == 0)
                {
                    return(new ContentResult {
                        Content = "<p>There are no such courses.</p>"
                    });
                }

                foreach (var course in courses)
                {
                    course.Lecturer = _courseRepository.GetWithLecturer(course.CourseId)?.Lecturer;
                }

                return(PartialView("CoursesList", courses));
            }

            return(new ContentResult {
                Content = "<p>There are no such courses.</p>"
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Register(StudentViewModel studentView)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser student = new Domain.Core.Student
                {
                    BirthDate   = studentView.BirthDate,
                    FirstName   = studentView.FirstName,
                    Gender      = studentView.Gender,
                    Group       = studentView.Group,
                    LastName    = studentView.LastName,
                    MiddleName  = studentView.MiddleName,
                    PhoneNumber = studentView.PhoneNumber,
                    UserName    = studentView.UserName,
                    YearOfStudy = studentView.YearOfStudy,
                    Email       = studentView.Email
                };
                var result = await UserManager.CreateAsync(student, studentView.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRoles(student.Id, "student", "active");
                    _logger.Info($"New student {student.UserName} register in the system.");

                    return(RedirectToAction("Login", "Account", new { area = "" }));
                }
                foreach (string error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                    _logger.Error("Register method of controller Student: Error creating a user.", error);
                }
            }

            return(View(studentView));
        }
Exemplo n.º 3
0
        /// <summary>
        /// View info about student and his courses. View contains partialView.
        /// </summary>
        public ActionResult Index()
        {
            Domain.Core.Student user = (Domain.Core.Student)UserManager.FindByNameAsync(User.Identity.Name).Result;
            if (user != null)
            {
                if (User.IsInRole("active"))
                {
                    ViewBag.Active = "Profile is active";
                    return(View(user));
                }

                ViewBag.Active = "Profile is blocked by Admin";
                return(View(user));
            }
            _logger.Warn("Index method of controller Student: user=null, user received HttpNotFound");
            return(HttpNotFound());
        }
Exemplo n.º 4
0
        public ActionResult EnrollForCourse(int id)
        {
            Domain.Core.Student user = (Domain.Core.Student)UserManager.FindByNameAsync(User.Identity.Name).Result;
            if (User.IsInRole("active"))
            {
                if (user != null)
                {
                    var course = _courseRepository.Get(id);
                    if (course != null)
                    {
                        _courseRepository.AddStudentToCourse(user.UserName, id);
                        UserManager.Update(user);
                    }
                }
                else
                {
                    _logger.Warn("EnrollForCourse method of controller Student: user=null, user received HttpUnauthorizedResult");
                    return(new HttpUnauthorizedResult());
                }
            }

            return(RedirectToAction("Index"));
        }