本文整理汇总了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;
}
示例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"));
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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");
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
}
示例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");
}
}
示例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);
}
示例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;
}
}