当前位置: 首页>>代码示例>>C#>>正文


C# ApplicationUserManager.FindByIdAsync方法代码示例

本文整理汇总了C#中ApplicationUserManager.FindByIdAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUserManager.FindByIdAsync方法的具体用法?C# ApplicationUserManager.FindByIdAsync怎么用?C# ApplicationUserManager.FindByIdAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApplicationUserManager的用法示例。


在下文中一共展示了ApplicationUserManager.FindByIdAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMedicationDetails

        public async static Task<Tuple<List<Medication>, Hl7.Fhir.Model.Patient>> GetMedicationDetails(string id, ApplicationUserManager userManager)
        {
            Tuple<List<Medication>, Hl7.Fhir.Model.Patient> tup;
            using (var dbcontext = new ApplicationDbContext())
            {
                // Should be FhirID
                var user = await userManager.FindByIdAsync(id);
                if (user == null)
                {
                    return null;
                }

                var client = new FhirClient(Constants.HapiFhirServerBase);
                if (string.IsNullOrWhiteSpace(user.FhirPatientId))
                {
                    var result = client.Create(new Hl7.Fhir.Model.Patient() { });
                    user.FhirPatientId = result.Id;
                    await userManager.UpdateAsync(user);
                }
                var patient = client.Read<Hl7.Fhir.Model.Patient>(Constants.PatientBaseUrl + user.FhirPatientId);
                tup= new Tuple<List<Medication>, Patient>(await EhrBase.GetMedicationDataForPatientAsync(user.FhirPatientId, client), patient);
                return tup;
            }

        }
开发者ID:EhrgoHealth,项目名称:CS6440,代码行数:25,代码来源:EhrBase.cs

示例2: OnActionExecuting

        internal void OnActionExecuting(
            ActionExecutingContext filterContext, 
            ApplicationUserManager userManager,
            ClientIdCalculator clientIdCalculator)
        {
            if (filterContext.ActionParameters.ContainsKey(USER_CONTEXT_KEY))
            {
                ApplicationUser applicationUser;

                if (filterContext.HttpContext.User.Identity.IsAuthenticated)
                {
                    string userId = filterContext.HttpContext.User.Identity.GetUserId();
                    applicationUser = userManager.FindByIdAsync(userId).Result;
                }else
                {
                    applicationUser = new AnonymousApplicationUser();
                    if (this.RequiresGamingGroup)
                    {
                        filterContext.Result = new RedirectToRouteResult(MVC.Account.Login().GetRouteValueDictionary());
                    }
                }

                applicationUser.AnonymousClientId = clientIdCalculator.GetClientId(filterContext.HttpContext.Request, applicationUser);

                filterContext.ActionParameters[USER_CONTEXT_KEY] = applicationUser;
            }

            base.OnActionExecuting(filterContext);
        }
开发者ID:NemeStats,项目名称:NemeStats,代码行数:29,代码来源:UserContextAttribute.cs

示例3: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            this.manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

            this.currentUser = manager.FindByIdAsync(User.Identity.GetUserId()).Result;

            if (this.currentUser == null)
            {
                Response.Redirect("/Account/Login");
            }

            this.firstName.Attributes.Add("placeholder", currentUser.FirstName);
            this.lastName.Attributes.Add("placeholder", currentUser.LastName);
            //this.firstName.Text = currentUser.FirstName;
            //this.lastName.Text = currentUser.LastName;
        }
开发者ID:BooksLibrary,项目名称:BooksLibrary,代码行数:16,代码来源:ManagePersonalInfo.aspx.cs

示例4: Disconnect

        public async Task<ActionResult> Disconnect(ApplicationSignInManager signInManager, ApplicationUserManager userManager, string provider, string userId, string redirectUri)
        {
            var userLoginInfo = (await userManager.GetLoginsAsync(userId)).First(x => x.LoginProvider == provider);

            var result = await userManager.RemoveLoginAsync(userId, userLoginInfo);
            if (result.Succeeded)
            {
                var user = await userManager.FindByIdAsync(userId);
                if (user != null)
                {
                    await signInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                }
            }
            else
            {
                Logger.Error($"Unable to disconnect {provider} from user {userId}");
            }
            return new RedirectResult(redirectUri);
        }
开发者ID:aduggleby,项目名称:dragon,代码行数:19,代码来源:FederationService.cs

示例5: InsertOrUpdate

        public async Task<bool> InsertOrUpdate(IdentityUserViewModel model, ApplicationUserManager userManager)
        {

            var user = await userManager.FindByIdAsync(model.Id);

            if (user == null)
            {
                user = new ApplicationUser();
                user.Assign(model);


                var result = await userManager.CreateAsync(user, "1234567");
                if (!result.Succeeded) return false;
                model.Id = user.Id;
            }
            else
            {
                user.Email = model.Email;
                user.UserName = model.UserName;
                user.DUI = model.DUI;
                user.PhoneNumber = model.PHONE_2;
                user.ADDRESS = model.ADDRESS;
                user.Category = model.Category;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.DUI = model.DUI;
                user.PHONE_2 = model.PHONE_2;
                user.ProfilePicture = model.ProfilePicture;
                user.CenterId = model.CenterId;
                //user.Address = model.Address;
                //user.FirstName = model.FirstName;
                //user.LastName = model.LastName;
                //user.DocumentNum = model.DocumentNum;
                //user.ProfilePicture = model.ProfilePicture;
                await userManager.UpdateAsync(user);
            }

            if (model.ForceChangePassword)
            {
                var tok = await userManager.GeneratePasswordResetTokenAsync(model.Id);

                var result = await userManager.ResetPasswordAsync(model.Id, tok, model.Password);

                if (!result.Succeeded) return false;
            }
            var roles = await userManager.GetRolesAsync(model.Id);

            if (!roles.Any() && !string.IsNullOrEmpty(model.Role))
            {
                var res = await userManager.AddToRoleAsync(model.Id, model.Role);
            }

            if (roles.All(r => r != model.Role) && roles.Any())
            {
                var result = await userManager.AddToRoleAsync(model.Id, model.Role);
            }
            roles.Where(r => r != model.Role).ToList().ForEach(role => userManager.RemoveFromRole(model.Id, role));

            if (model.CenterId != 0)
            {

                var claim = await Context.UserClaims.FirstOrDefaultAsync(c => c.UserId == user.Id && c.ClaimType == "CenterId");

                var claims = await userManager.GetClaimsAsync(user.Id);
                if (claim != null)
                {
                    claim.ClaimValue = model.CenterId.Value.ToString();
                    await Context.SaveChangesAsync();
                }
                else
                {
                    await userManager.AddClaimAsync(model.Id, new System.Security.Claims.Claim("CenterId", model.CenterId.ToString()));
                }
            }


            return true;
        }
开发者ID:QualityConsultingTeam,项目名称:Cancha,代码行数:78,代码来源:IdentityManagerService.cs

示例6: UpdateRoles

        public async Task<IdentityResult> UpdateRoles(JObject roles)
        {
            string userId = ((dynamic)roles).Id.Value;
            string roleId = ((dynamic)roles).RoleId.Value;
            string roleName = ((dynamic)roles).RoleName.Value;

            IdentityResult result = null;

            #region TODO: Remove unused commented code
            //IdentityRole role = (from r in _contextProvider.Context.Roles where r.Id == roleId select r).FirstOrDefault();
            //var user = _contextProvider.Context.Users.Where(x => x.Id == userId).FirstOrDefault();
            //if (user.Roles.Any(x => x.RoleId == roleId))
            //{
            //    // User is in the Admin Role

            //}
            //else
            //{

            //    //User is not in the Admin Role
            //}

            //var role = (from r in _contextProvider.Context.Roles where r.Id == roleId select r).FirstOrDefault();
            //var users = _contextProvider.Context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains(role.Id)).ToList();
            //if (users.Find(x => x.Id == userId) != null)
            //{
            //    // User is in the Admin Role
            //}
            //else
            //{

            //    //User is not in the Admin Role
            //}
            #endregion

            var userStore = new UserStore<ApplicationUser>(_contextProvider.Context);
            var userManager = new ApplicationUserManager(userStore);

            var roleStore = new RoleStore<IdentityRole>(_contextProvider.Context);
            var roleManager = new ApplicationRoleManager(roleStore);

            ApplicationUser user = await userManager.FindByIdAsync(userId);//.ConfigureAwait(false);

            IList<string> role = new List<string>();
            role.Add(roleName);
            if (user.Roles.Any(x => x.RoleId == roleId))
            {
                //remove user and roll mapping
                result = await userManager.RemoveUserFromRolesAsync(userId, role).ConfigureAwait(false);
                result = await userManager.RemoveClaimAsync(userId, new Claim(IdentityConstants.ClaimTypes.Role, roleName));
            }
            else
            {
                result = await userManager.AddUserToRolesAsync(userId, role).ConfigureAwait(false);
                result = await userManager.AddClaimAsync(userId, new Claim(IdentityConstants.ClaimTypes.Role, roleName));

                //User is not in the Admin Role
            }
            #region TODO: Remove unused commented code
            //if (user.Roles.Count > 0)
            //{
            //    var roleExists = user.Roles.First(x => x.RoleId == roleId);
            //    if (roleExists != null)
            //    {
            //        //remove user and roll mapping
            //        //result = await userManager.RemoveFromRoleAsync(userId, roleId).ConfigureAwait(false);
            //        //remove user and its claim
            //        //Claim c = new Claim();
            //        //c.Type = "role";
            //        //c.Value
            //        //result = await userManager.RemoveClaimAsync(userId,new Claim() { })

            //    }
            //    else
            //    {
            //        //result = await userManager.AddToRoleAsync(userId,roleId);
            //    }

            //}
            #endregion
            return await userManager.UpdateAsync(user).ConfigureAwait(false);
        }
开发者ID:szwork2013,项目名称:BoiPlt,代码行数:82,代码来源:UserManagerController.cs

示例7: DeleteUser

        public async Task<ActionResult> DeleteUser(string Username)
        {
            try
            {
                var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context));
                ApplicationUser user = context.Users.Where(u => u.UserName.Equals(Username, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

                string userID = user.Id;

                if (ModelState.IsValid)
                {
                    if (userID == null)
                    {
                        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                    }

                    var userDel = await manager.FindByIdAsync(userID);
                    var logins = user.Logins;

                    foreach (var login in logins.ToList())
                    {
                        await manager.RemoveLoginAsync(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
                    }

                    var rolesForUser = await manager.GetRolesAsync(userID);

                    if (rolesForUser.Count() > 0)
                    {
                        foreach (var item in rolesForUser.ToList())
                        {
                            // item should be the name of the role
                            var result = await manager.RemoveFromRoleAsync(user.Id, item);
                        }
                    }

                    await manager.DeleteAsync(user);

                    TempData["ValidationMessage"] = ("Success: " + " " + Username + " " + "Was Removed");
                    return View("ManageUser");
                }
                else
                {
                    TempData["ValidationMessage"] = ("Error: " + " " + Username + " " + "Was Not Removed");
                    return View("ManageUser");
                }
            }
            catch
            {
                TempData["ValidationMessage"] = ("Error: Something Went Wrong");
                return View("ManageUser");
            }

        }
开发者ID:amoryjh,项目名称:MVC-HPFS,代码行数:53,代码来源:UserController.cs


注:本文中的ApplicationUserManager.FindByIdAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。