本文整理汇总了C#中ApplicationUserManager.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUserManager.Update方法的具体用法?C# ApplicationUserManager.Update怎么用?C# ApplicationUserManager.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationUserManager
的用法示例。
在下文中一共展示了ApplicationUserManager.Update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainTest
public void MainTest()
{
var uman = new ApplicationUserManager( new UserStore<SnooNotesAPI.Models.ApplicationUser>( new ApplicationDbContext() ) );
var ident = uman.FindByName( "snoonotes" );
foreach(var claim in uman.GetClaims( ident.Id ) ) {
uman.RemoveClaim( ident.Id, claim );
}
ident.Claims.Add( new IdentityUserClaim() { UserId = ident.Id, ClaimType = "urn:snoonotes:subreddits:goawaynoonelikesyou:admin", ClaimValue = "true" } );
ident.Claims.Add( new IdentityUserClaim() { UserId = ident.Id, ClaimType = ClaimsIdentity.DefaultRoleClaimType, ClaimValue = "gooaway" } );
uman.Update( ident );
uman.Dispose();
Program.Main( new string[] { "goawaynoonelikesyou", "gooaway","snoonotes" } );
uman = new ApplicationUserManager( new UserStore<SnooNotesAPI.Models.ApplicationUser>( new ApplicationDbContext() ) );
ident = uman.FindByName( "snoonotes" );
if ( ident.Claims.Any( c => c.ClaimType == "urn:snoonotes:subreddits:goawaynoonelikesyou:admin" ) ) Assert.Fail( "Admin claim not removed." );
if ( ident.Claims.Any( c => c.ClaimType == ClaimsIdentity.DefaultRoleClaimType && c.ClaimValue == "gooaway" ) ) Assert.Fail( "Invalid sub claim not removed" );
if ( !ident.Claims.Any( c => c.ClaimType == ClaimsIdentity.DefaultRoleClaimType && c.ClaimValue == "snoonotes" ) ) Assert.Fail( "Access roll not added" );
if ( !ident.Claims.Any( c => c.ClaimType == ClaimsIdentity.DefaultRoleClaimType && c.ClaimValue == "goawaynoonelikesyou" ) ) Assert.Fail( "Access roll not added" );
if ( !ident.Claims.Any( c => c.ClaimType == "urn:snoonotes:subreddits:snoonotes:admin" && c.ClaimValue == "true" ) ) Assert.Fail( "Admin roll not added" );
}
示例2: UpdateUserComputerInfo
public static void UpdateUserComputerInfo(ApplicationUser user, ApplicationUserManager userManager)
{
var computerInfo = GetSpecs();
user.Device = computerInfo[0] ?? "";
user.Os = computerInfo[1] ?? "";
user.Browser = computerInfo[2] ?? "";
user.ComputerInfo = computerInfo[3] ?? "";
user.LastActivityDate=DateTime.UtcNow;
user.UtcOffSet = TimeDateServices.GetUtcOffSet();
try
{
userManager.Update(user);
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
var errorMessage = dbEx.EntityValidationErrors.Aggregate("", (current1, validationErrors) => validationErrors.ValidationErrors.Aggregate(current1, (current, validationError) => current + ($"{validationErrors.Entry.Entity.ToString()}:{validationError.ErrorMessage}" + ", \r\n")));
Log4NetHelper.Log(errorMessage, LogLevel.ERROR, "UpdateComputerInfo", 1, user.UserName, dbEx);
}
}
示例3: CreatePatient
public ActionResult CreatePatient(CreatePatientViewModel model)
{
ApplicationUser user = UserManager.FindById(User.Identity.GetUserId());
Physician physician = _physicianService.GetPhysician(user.PhysicianId);
// Conversions from the model
int race = (int)Enum.Parse(typeof(PatientRace), model.Race);//convert.GenderRaceStringToInt(model.Race);
int gender = (int)Enum.Parse(typeof(PatientGender), model.Gender);//convert.PatientGenderStringToInt(model.Gender);
int ethnicity = (int)Enum.Parse(typeof(PatientEthnicity), model.Ethnicity);// convert.PatientEthnicityStringToInt(model.Ethnicity);
// Check if the user is already in the database.
if (UserIsInDatabase(model.Username))
{
// User is already in the database
// Display an error and request the physician to enter in a different username.
ModelState.Clear();
ModelState.AddModelError("UsernameExistsError", "Username already exists.");
}
else
{
// User is not in the database.
// Proceed to add the user to the database.
Patient patient = new Patient();
patient.Birthdate = DateTime.Parse(model.Birthdate); //model.Birthdate; // Need to fix this, temporarily putting in 0.
patient.Height = (int)model.Height;
patient.Weight = (int)model.Weight;
patient.Location = (int)Enum.Parse(typeof(Location), model.Location);//model.Location; // Need to fix this. temporarily putting in 12.
patient.Ethnicity = ethnicity;
patient.Gender = gender;
patient.Race = race;
patient.Physician = physician;
var newUser = new ApplicationUser { UserName = model.Username, Status = (int)Account_Status.Active };
if ((newUser != null) && (model.Password != null))
{
//Create a new context to change the user creation validation rules for the patient only.
using (ApplicationDbContext context = new ApplicationDbContext()) {
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context));
// This user validator is being created only to remove email as a required field for creating a user.
// The email field in the AspNetUsers table is nullable and our requirments state that a patient does not
// have an email address so in order to satisfy that requiremnt we need to remove the required email
// parameter on user creation validation.
manager.UserValidator = new UserValidator<ApplicationUser>(manager) {
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = false
};
var result = manager.Create(newUser, model.Password);
if (result.Succeeded) {
// User added to database successfully.
_patientService.CreatePatient(patient);
_patientService.SaveChanges();
newUser.PatientId = patient.Id;
result = manager.Update(newUser);
//Role must match what is found in the database AspNetRoles table.
result = manager.AddToRole(newUser.Id, "Patient");
physician.Patients.Add(patient);
_physicianService.UpdatePhysician(physician);
_physicianService.SaveChanges();
}
else {
// User failed to add.
ModelState.Clear();
foreach (string error in result.Errors) {
ModelState.AddModelError("ResultError", error);
}
return View(model);
}
}
}
else
{
// Username or password was null if we got here.
}
}
return View(model);
}