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


C# UserManager.Update方法代码示例

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


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

示例1: UpdateUser

 internal bool UpdateUser(string username, string realUsername, string permission)
 {
     IdentityResult result = null;
     Models.ApplicationDbContext context = new Models.ApplicationDbContext();
     var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
     var user = userMgr.FindByName(username);
     if (!string.IsNullOrEmpty(realUsername))
     {
         user.RealUserName = realUsername;
         result = userMgr.Update(user);
     }
     if (!string.IsNullOrEmpty(permission) && !userMgr.IsInRole(user.Id, permission))
     {
         userMgr.RemoveFromRoles(user.Id, "read", "edit", "administrator");
         switch (permission)
         {
             case "administrator":
                 result = userMgr.AddToRole(user.Id, "administrator");
                 break;
             case "edit":
                 result = userMgr.AddToRole(user.Id, "edit");
                 break;
             default:
                 result = userMgr.AddToRole(user.Id, "read");
                 break;
         }
     }
     if (result == IdentityResult.Success) return true; else return false;
 }
开发者ID:OurFirstOrgan,项目名称:FlyingSnow.Travel,代码行数:29,代码来源:RoleActions.cs

示例2: ChangeAcessMode

        public ActionResult ChangeAcessMode(ScheduleAccessMode mode)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            if (HttpContext.User.IsInRole("Admin"))
            {
                var userStore = new UserStore<ApplicationUser>(context);
                var userManager = new UserManager<ApplicationUser>(userStore);

                string userName = HttpContext.User.Identity.GetUserName();
                var adminUser = userManager.FindByName(userName);
                adminUser.ScheduleAccessMode = mode;
                try
                {
                    userManager.Update(adminUser);
                }
                catch (Exception ex)
                {
                    return RedirectToAction("View","Error",new CustomError(ex.Message));
                }
                string previousUrl = System.Web.HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
                //return RedirectToAction("View", "Schedule", new { course = 1 });
                return Redirect(previousUrl);
            }
            return RedirectToAction("View", "Error", new CustomError("Access Denied"));
        }
开发者ID:vadimberkut,项目名称:dias-schedule,代码行数:25,代码来源:ScheduleController.cs

示例3: MapUserToPerson

 public bool MapUserToPerson(ApplicationUser user,Person person)
 {
     var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new EntityDbContext()));
     user.Person = person;
     var idResult = um.Update(user);
     return idResult.Succeeded;
 }
开发者ID:nongzhsh,项目名称:Nccq,代码行数:7,代码来源:IdentityManager.cs

示例4: Update

 public void Update(ApplicationUser user)
 {
     var store = new UserStore<ApplicationUser>(this.Context);
     var userManager = new UserManager<ApplicationUser>(store);
     var context = store.Context;
     userManager.Update(user);
     context.SaveChanges();
 }
开发者ID:ivanvasilev,项目名称:PickUp,代码行数:8,代码来源:UsersService.cs

示例5: DisableUser

        public async Task<ActionResult> DisableUser(string userName)
        {

   
            List<string> users;
            List<string> enabledUsers;
            List<string> disabledUsers;
            using (var context = new ApplicationDbContext())
            {

                var userStore = new UserStore<ApplicationUser>(context);
                var userManager = new UserManager<ApplicationUser>(userStore);

                var selectedUser = userManager.FindByName(userName);

                if (selectedUser == null)
                    throw new Exception("User not found!");

                if (!selectedUser.UserName.Equals("[email protected]"))
                {


                    if (!selectedUser.LockoutEnabled)
                    {
                        userManager.SetLockoutEnabled(selectedUser.Id, true);
                        DateTime lockoutDate = DateTime.Now.AddYears(50);
                        await userManager.SetLockoutEndDateAsync(selectedUser.Id, lockoutDate);
                        context.SaveChanges();
                        userManager.Update(selectedUser);
                        ViewBag.ResultMessage = "Disabled successfully !";

                    }
                }
                else
                {
                    ViewBag.ResultMessage = "Cannot disable Admin";
                }

                users = (from u in userManager.Users select u.UserName).ToList();
                disabledUsers = new List<string>(users);
                enabledUsers = new List<string>(users);
                foreach (var user in users)
                {
                    if (!userManager.FindByName(user).LockoutEnabled)
                    {
                        disabledUsers.Remove(user);
                    }
                    else
                    {
                        enabledUsers.Remove(user);
                    }
                }
            }

            ViewBag.EnabledUsers = new SelectList(enabledUsers);
            ViewBag.DisabledUsers = new SelectList(disabledUsers);
            return View();
        }
开发者ID:Jestersage,项目名称:comp4870asn03,代码行数:58,代码来源:RoleController.cs

示例6: btnSave_OnClick

        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            var ddlRestaurant = GetDdlValue(fvRestaurateur, "ddlRestaurant");
            var ddlUsers = GetDdlValue(fvRestaurateur, "ddlUsers");

            var rstManager = new RestaurantManager();
            var clientManager = new ClientManager();
            var userManager = new UserManager();

            if (fvRestaurateur.CurrentMode == FormViewMode.Edit)
            {
                var client = clientManager.Get(currentId);
                client.Restaurant = rstManager.Get(ddlRestaurant);

                var user = userManager.Get(ddlUsers);
                user.Position = Role.Restaurateur;
                userManager.Update(user);
                client.UserInfo = user;
                clientManager.Update(client);

            }
            else if (fvRestaurateur.CurrentMode == FormViewMode.Insert)
            {
                var client = new ClientInfo();
                client.Restaurant = rstManager.Get(ddlRestaurant);

                var user = userManager.Get(ddlUsers);

                user.Position = Role.Restaurateur;
                userManager.Update(user);
                client.UserInfo = user;

                clientManager.Add(client);

            }
            PopupHelper.HidePopup("#pop", this);
            gvClients.DataBind();
        }
开发者ID:pasha369,项目名称:RestaurantManagementSystem,代码行数:38,代码来源:Users.aspx.cs

示例7: ChangeTheme

        public ActionResult ChangeTheme(string themename)
        {
            var userStore = new UserStore<ApplicationUser>(new ApplicationDbContext());
            var manager = new UserManager<ApplicationUser>(userStore);
            var user = manager.FindById(User.Identity.GetUserId());
            user.CssTheme = themename;
            manager.Update(user);

            if (Request.UrlReferrer != null)
            {
                var returnUrl = Request.UrlReferrer.ToString();
                return new RedirectResult(returnUrl);
            }
            return RedirectToAction("Index", "Home");
        }
开发者ID:igor-rif-shevchenko,项目名称:BootstrappingMvc-Code,代码行数:15,代码来源:ProfileController.cs

示例8: UploadPhoto

        public void UploadPhoto()
        {
            var httpRequest = HttpContext.Current.Request;
            var imageFile = httpRequest.Files["file0"];

            if(imageFile != null)
            {
                var userManager = new UserManager();
                var photoUrl = this.SavePhoto(imageFile);

                var user = userManager.Get()
                    .FirstOrDefault(u => u.Login == HttpContext.Current.User.Identity.Name);
                user.PhotoUrl = photoUrl;
                userManager.Update(user);
            }
        }
开发者ID:pasha369,项目名称:RestaurantManagementSystem,代码行数:16,代码来源:ImageController.cs

示例9: Edit

        public ActionResult Edit(User input)
        {
            UserManager manager = new UserManager();
            User user = manager.findById(input.Id);

            if (ModelState.IsValid) {
                //db.Users.Attach(userprofile);
                //db.Entry(userprofile).Property(x => x.Active).IsModified = true;
                //db.SaveChanges();

                user.Active = input.Active;
                manager.Update(user);

                return RedirectToAction("Index");
            }
            return View(user);
        }
开发者ID:OzzieSoft,项目名称:SrPrjGrp2,代码行数:17,代码来源:AdministratorController.cs

示例10: Update

        public static IdentityResult Update(this ApplicationUser user)
        {
            using (
                var userManager =
                    new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
            {

                var userUpdated = userManager.FindById(user.Id);

                userUpdated.Name = user.Name;
                userUpdated.LastName = user.LastName;
                userUpdated.PhoneNumber = user.PhoneNumber;
                userUpdated.AlterPhoneNumber = user.AlterPhoneNumber;
                userUpdated.Email = user.Email;
                userUpdated.AlterEmail = user.AlterEmail;
                userUpdated.UserName = user.UserName;

                return userManager.Update(userUpdated);
            }
        }
开发者ID:yerald231ger,项目名称:EmmtyMr,代码行数:20,代码来源:ApplicationUserExtencion.cs

示例11: ProfileForm_UpdateItem

        // The id parameter name should match the DataKeyNames value set on the control
        public void ProfileForm_UpdateItem(int? id)
        {
            var manager = new UserManager();

            var user = manager.FindByName(User.Identity.Name);

            var item = user.Profile;

            // Load the item here, e.g. item = MyDataLayer.Find(id);
            if (item == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                return;
            }
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                manager.Update(user);
                // Save changes here, e.g. MyDataLayer.SaveChanges();
            }
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:23,代码来源:ProfileManagement.aspx.cs

示例12: setPassword_Click

        protected void setPassword_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                // Create the local login info and link the local account to the user
                UserManager manager = new UserManager();

                var user = manager.FindById(User.Identity.GetUserId());

                IdentityResult result = manager.AddPassword(user.Id, password.Text);

                if (result.Succeeded)
                {
                    user.IsApproved = true;
                    manager.Update(user);

                    Response.Redirect("~/IdentityAccount/Manage.aspx?m=SetPwdSuccess");
                }
                else
                {
                    AddErrors(result);
                }
            }
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:24,代码来源:Manage.aspx.cs

示例13: btnAddUser_Click

        protected void btnAddUser_Click(object sender, EventArgs e)
        {
            try
            {
                using (ApplicationDbContext ctx = new ApplicationDbContext())
                {
                    //var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
                    var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ctx));
                    Logic.CustomUserValidator customerUserValidator = new Logic.CustomUserValidator();
                    manager.UserValidator = customerUserValidator;
                    var user = new ApplicationUser()
                    {
                        UserName = txtUsername.Text,
                        FirstName = txtFirstName.Text,
                        LastName = txtLastName.Text,
                        Email = txtEmail.Text,
                        PhoneNumber = txtPhone.Text,
                        Status = ctx.UserStatuses.First(us => us.StatusDescription == "Active"),
                        HasBeenDisassociated = false,
                        DisassociatedMerchant = null
                    };

                    String randomPassword = CreatePassword();

                    IdentityResult result = manager.Create(user, randomPassword);

                    if (result.Succeeded)
                    {
                        lblNewUserMessage.Text = "";

                        ApplicationUser newUser = manager.FindByName(user.UserName);

                        if (newUser != null)
                        {
                            if (!manager.IsInRole(newUser.Id, "Merchant"))
                            {
                                manager.AddToRole(newUser.Id, "Merchant");
                                manager.Update(newUser);
                                ctx.SaveChanges();
                            }

                        }
                        else
                        {
                            lblNewUserMessage.Text = "An error occurred while adding the new user.  Please contact your system administrator before continuing.";
                        }

                        NewUserAdded();

                        btnContinueAddUser.Visible = true;
                        btnCancelAddUser.Visible = false;
                        btnAddUser.Visible = false;
                    }
                    else
                    {
                        lblNewUserMessage.Text = result.Errors.FirstOrDefault();
                    }
                }
            }
            catch (System.Exception ex)
            {
                _newLogic.WriteExceptionToDB(ex, "btnAddUser_Click");
            }
        }
开发者ID:WCTingle,项目名称:InfoShare_Public,代码行数:64,代码来源:Merchants.aspx.cs

示例14: Edit

        public ActionResult Edit([Bind(Include = "FirstName,LastName,Email,PhoneNumber,UserName")] ApplicationUser applicationUser)
        {
            if (ModelState.IsValid)
            {
                var userStore = new UserStore<ApplicationUser>(db);
                var userManager = new UserManager<ApplicationUser>(userStore);

                string userId = userManager.FindByName(applicationUser.UserName).Id;

                userManager.RemoveFromRoles(userId, userManager.GetRoles(userId).ToArray());
                userManager.AddToRoles(userId, Request["Role"].Split(','));

                userManager.Update(applicationUser);

                return RedirectToAction("Index");
            }
            return View(applicationUser);
        }
开发者ID:ChrisSallee,项目名称:Kanban,代码行数:18,代码来源:ApplicationUsersController.cs

示例15: UpdateUserByID

        public void UpdateUserByID(string userID, string email)
        {
            try
            {
                var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context1));
                var userToUpdate1 = userMgr.FindById(userID);
                    userToUpdate1.Email = email;
                userMgr.Update(userToUpdate1);

            }
            catch (OptimisticConcurrencyException ocex)
            {
                throw ocex;
            }
            catch (ArgumentNullException argex)
            {
                throw argex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:Tom2Filip,项目名称:AddressBook,代码行数:23,代码来源:ApplicationUserRepository.cs


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