示例#1
0
 private void BtnSave_Click()
 {
     if (SelectedApplicationUsers.Password.Length >= 6)
     {
         _applicationUserRepository.UpdateUser(SelectedApplicationUsers);
         ReadUsers();
         SelectedApplicationUserRoles = new ApplicationUserRoles()
         {
             RoleName = ""
         };
     }
 }
示例#2
0
 private void BtnDelete_Click()
 {
     if (SelectedApplicationUsers != null)
     {
         _applicationUserRepository.DeleteUser(SelectedApplicationUsers);
         ReadUsers();
         SelectedApplicationUserRoles = new ApplicationUserRoles()
         {
             RoleName = ""
         };
     }
 }
示例#3
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    OtherName = model.OtherNames,
                    UserName  = model.UserName,
                    Email     = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var userType = model.UserType;

                    if (userType == ShevaUserType.Patient)
                    {
                        if (!_roleManager.RoleExistsAsync("Patient").Result)
                        {
                            ApplicationUserRoles role = new ApplicationUserRoles();
                            role.Name     = "Patient";
                            role.UserType = ShevaUserType.Patient;

                            IdentityResult roleResult = _roleManager.CreateAsync(role).Result;

                            if (!roleResult.Succeeded)
                            {
                                ModelState.AddModelError("", "Error While creating Role!");
                                return(View(model));
                            }
                        }
                        await _userManager.AddToRoleAsync(user, "Patient");
                    }
                    else if (userType == ShevaUserType.CareGiver)
                    {
                        if (!_roleManager.RoleExistsAsync("CareGiver").Result)
                        {
                            ApplicationUserRoles role = new ApplicationUserRoles();
                            role.Name     = "CareGiver";
                            role.UserType = ShevaUserType.CareGiver;

                            IdentityResult roleResult = _roleManager.CreateAsync(role).Result;

                            if (!roleResult.Succeeded)
                            {
                                ModelState.AddModelError("", "Error While creating Role!");
                                return(View(model));
                            }
                        }
                        await _userManager.AddToRoleAsync(user, "CareGiver");
                    }

                    _logger.LogInformation("User created a new account with password.");

                    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(RedirectToAction("DashBoard", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#4
0
 private void AssignRoleToUser(ApplicationUserRoles selectedApplicationUserRoles)
 {
     SelectedApplicationUsers.RoleId = selectedApplicationUserRoles.Id;
     SelectedApplicationUsers.role   = selectedApplicationUserRoles;
 }