예제 #1
0
        public async Task <ActionResult> Confirm(InstructorAccountViewModel viewModel)
        {
            var user = await UserManager.FindByEmailAsync(viewModel.EmailAdress);

            //Send an email with this link


            string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
            await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

            return(View("EmailConfirmation"));
        }
예제 #2
0
        public async Task <ActionResult> CreateAccountForInstructor()
        {
            var userManager = new ApplicationUserManager(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var user        = await userManager.FindByNameAsync(User.Identity.Name);

            var deptHead = user == null ? null : _context.Instructors.Include(i => i.Department.Instructors).Single(i => i.AccountId == user.Id);

            var viewModel = new InstructorAccountViewModel
            {
                Department = deptHead.Department
            };

            return(View(viewModel));
        }
예제 #3
0
        public async Task <ActionResult> CreateAccountForInstructor(InstructorAccountViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = viewModel.EmailAdress, Email = viewModel.EmailAdress
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    var identityResult = UserManager.AddToRole(user.Id, RoleName.IsAnInstructor);

                    if (identityResult.Succeeded)
                    {
                        using (var schedulingContext = new SchedulingContext())
                        {
                            var instructorInDb = schedulingContext.Instructors.SingleOrDefault(i => i.Id == viewModel.InstructorId);

                            if (instructorInDb != null)
                            {
                                instructorInDb.AccountId = user.Id;
                                schedulingContext.SaveChanges();
                            }
                        }
                    }
                }

                if (!result.Succeeded)
                {
                    viewModel = new InstructorAccountViewModel
                    {
                        ErrorMessages = result.Errors
                    };
                    return(View("CreateAccountForInstructor", viewModel));
                }
            }
            return(RedirectToAction("CreateAccountForInstructor"));
        }