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


C# ApplicationUserManager.AddPasswordAsync方法代码示例

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


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

示例1: Edit

        public async Task<ActionResult> Edit(UserDetailsViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var db = new ApplicationDbContext())
                {
                    MyUser user = db.Users.Find(model.UserId);

                    user.Id = model.UserId;
                    user.UserName = model.UserName;
                    user.Email = model.EmailAddress;
                    user.EmailConfirmed = model.EmailAddressConfirmed;
                    user.AccessFailedCount = model.AccessFailedCount;
                    user.LockoutEnabled = model.LockoutEnabled;
                    user.LockoutEndDateUtc = model.LockoutEndDate;

                    user.UserDetails.FirstName = model.FirstName;
                    user.UserDetails.LastName = model.LastName;
                    user.UserDetails.Age = model.Age;
                    user.UserDetails.Address = model.Address;
                    user.UserDetails.City = model.City;
                    user.UserDetails.Country = model.Country;

                    MyUserRole currentRole = db.Users.FirstOrDefault(m => m.Id == model.UserId)
                        .Roles.FirstOrDefault();

                    db.Users.FirstOrDefault(m => m.Id == model.UserId)
                        .Roles.Remove(currentRole);
                    db.Users.FirstOrDefault(m => m.Id == model.UserId)
                        .Roles.Add(new MyUserRole { RoleId = int.Parse(model.Role), UserId = model.UserId });

                    db.Entry(user).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    ApplicationUserManager userManager = new ApplicationUserManager(new MyUserStore(new ApplicationDbContext()));

                    // Dodati da se novi password salje ;)

                    await userManager.RemovePasswordAsync(model.UserId);
                    await userManager.AddPasswordAsync(model.UserId, model.Password);
                }
                return RedirectToAction("Index", new { Message = UserMessageId.ChangeUser });
            }

            ViewBag.Roles = new SelectList(db.Roles.AsEnumerable().ToList(),
                "Id", "Name", db.Roles.FirstOrDefault(m => m.Id.ToString() == model.Role));

            ViewBag.Id = new SelectList(db.UserDetails, "Id", "Role", model.Role);
            return View(model);
        }
开发者ID:nikolamajcen,项目名称:rent-a-car,代码行数:50,代码来源:UsersController.cs

示例2: SetPassword

        public async Task<IHttpActionResult> SetPassword(SetPasswordBindingModel model)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            var manager = new ApplicationUserManager(new MySqlUserStore<ApplicationUser>());
            IdentityResult result = await manager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);

            if (!result.Succeeded)
                return GetErrorResult(result);

            return Ok();
        }
开发者ID:buddalasunil999,项目名称:ParkingInfringement,代码行数:13,代码来源:UsersController.cs


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