Exemplo n.º 1
0
        // GET: Relationship/StudentLessons
        public async Task <ActionResult> StudentLessons(string user, long id)
        {
            try
            {
                Teacher teacher = await _teacherRepositoryAsync.GetByUserAsync(user);

                List <Student> Students = await _studentRepositoryAsync.ListByUserAsync(user);

                Student student = await _studentRepositoryAsync.GetByIdAsync(id);

                List <StudentLesson> studentLessons  = student.StudentLessons;
                List <long>          assignedLessons = new List <long>();

                foreach (var lesson in studentLessons)
                {
                    assignedLessons.Add(lesson.LessonId);
                }

                RelationshipViewModel model = new RelationshipViewModel
                {
                    Teacher         = teacher,
                    Student         = student,
                    StudentLessons  = studentLessons,
                    AssignedLessons = assignedLessons
                };

                return(View(model));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        // GET: Student
        public async Task <ActionResult> Index(string user)
        {
            Teacher teacherData = await _teacherRepositoryAsync.GetByUserAsync(user);

            //Somehow adding this List of Students query will change the teacherData query to include StudentLessons (grandchild data), without this, all StudentLessons for Students is null.
            List <Student> Students = await _studentRepositoryAsync.ListByUserAsync(user);

            return(View(teacherData));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Setup(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    //Create new Teacher object
                    Teacher newTeacher = new Teacher
                    {
                        User        = user.Id,
                        FirstName   = model.FirstName,
                        LastName    = model.LastName,
                        Email       = model.Email,
                        CreatedBy   = user.Id,
                        CreatedDate = DateTime.Now,
                    };
                    //Add Teacher
                    var addTeacher = await _teacherRepositoryAsync.AddAsync(newTeacher);

                    //Add Claim
                    var addTeacherClaim = await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, "Teacher"));

                    //Get Teacher just added
                    var currentTeacher = await _teacherRepositoryAsync.GetByUserAsync(user.Id);

                    //Create new Course object
                    Course newCourse = new Course
                    {
                        User        = user.Id,
                        TeacherId   = currentTeacher.Id,
                        Title       = model.CourseTitle,
                        Description = model.CourseDescription,
                        StartDate   = model.StartDate,
                        EndDate     = model.EndDate,
                        CreatedBy   = user.Id,
                        CreatedDate = DateTime.Now
                    };
                    //Add Course
                    var addCourse = await _courseRepositoryAsync.AddAsync(newCourse);

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    //return RedirectToLocal(returnUrl); Old Value
                    return(RedirectToAction("Dashboard", "Teacher", new { user = user.Id }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 4
0
        // GET: Teacher/Dashboard/UserIdString(same as Identity Id)
        public async Task <ActionResult> Dashboard(string user)
        {
            var teacher = await _teacherRepositoryAsync.GetByUserAsync(user);

            return(View(teacher));
        }