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


C# ApplicationUserManager.Update方法代码示例

本文整理汇总了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" );
        }
开发者ID:CrustyJew,项目名称:SnooNotes,代码行数:26,代码来源:ProgramTests.cs

示例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);
            }

        }
开发者ID:rswetnam,项目名称:GoodBoating,代码行数:20,代码来源:UserComputer.cs

示例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);
        }
开发者ID:trwq63,项目名称:med656,代码行数:82,代码来源:PhysicianController.cs


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