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


C# UserManager.DeleteAsync方法代码示例

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


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

示例1: DeleteUser

        // delete a user account and all history: comments, posts and votes
        public static bool DeleteUser(string userName)
        {
            using (whoaverseEntities db = new whoaverseEntities())
            {
                using (UserManager<ApplicationUser> tmpUserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
                {
                    var tmpuser = tmpUserManager.FindByName(userName);
                    if (tmpuser != null)
                    {
                        //remove voting history for submisions
                        db.Votingtrackers.RemoveRange(db.Votingtrackers.Where(x => x.UserName == userName));

                        //remove voting history for comments
                        db.Commentvotingtrackers.RemoveRange(db.Commentvotingtrackers.Where(x => x.UserName == userName));

                        //remove all comments
                        var comments = db.Comments.Where(c => c.Name == userName);
                        foreach (Comment c in comments)
                        {
                            c.Name = "deleted";
                            c.CommentContent = "deleted";
                            db.SaveChangesAsync();
                        }

                        //remove all submissions
                        var submissions = db.Messages.Where(c => c.Name == userName);
                        foreach (Message s in submissions)
                        {
                            if (s.Type == 1)
                            {
                                s.Name = "deleted";
                                s.MessageContent = "deleted";
                                s.Title = "deleted";
                            }
                            else
                            {
                                s.Name = "deleted";
                                s.Linkdescription = "deleted";
                                s.MessageContent = "http://whoaverse.com";
                            }
                        }
                        db.SaveChangesAsync();

                        var result = tmpUserManager.DeleteAsync(tmpuser);
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }

            }
        }
开发者ID:jacobmason,项目名称:whoaverse,代码行数:55,代码来源:User.cs

示例2: RemoveTenantSampleData

        public async Task RemoveTenantSampleData(MyHealthContext context, UserManager<ApplicationUser> userManager, int tenantId)
        {
            if (context.Tenants.Any(t => t.TenantId == tenantId))
            {
                context.HomeAppointments.RemoveRange(context.HomeAppointments.Where(t => t.TenantId == tenantId));
                context.ClinicAppointments.RemoveRange(context.ClinicAppointments.Where(t => t.TenantId == tenantId));
                context.Medicines.RemoveRange(context.Medicines.Where(t => t.TenantId == tenantId));

                var usersToDelete = context.Users.Where(t => t.TenantId == tenantId).ToList();

                foreach (var user in usersToDelete)
                    await userManager.DeleteAsync(user);

                context.Tenants.Remove(context.Tenants.FirstOrDefault(t => t.TenantId == tenantId));
                await context.SaveChangesAsync();
            }
        }
开发者ID:Sirikon,项目名称:HealthClinic.biz,代码行数:17,代码来源:MyHealthDataInitializer.cs

示例3: DeleteUserByID

 public void DeleteUserByID(string userID)
 {
     try
     {
         var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context1));
         var userToDelete = userMgr.FindById(userID);
         userMgr.DeleteAsync(userToDelete);
     }
     catch (OptimisticConcurrencyException ocex)
     {
         throw ocex;
     }
     catch (ArgumentNullException argex)
     {
         throw argex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:Tom2Filip,项目名称:AddressBook,代码行数:21,代码来源:ApplicationUserRepository.cs

示例4: delete

        public Boolean delete()
        {
            //delete from user table
            String deleteUserID = Request.Params["id"];
            int id = int.Parse(deleteUserID);
            IRepository<User> repository = new UserRepository();
            User deletedUser = repository.findById(id);
            if (deletedUser == null)
            {
                return false;
            }
            repository.Delete(deletedUser);

            //delete from asp.netUser table
            var context = new NetCafeWeb.Models.ApplicationDbContext();
            var UserManager = new UserManager<NetCafeWeb.Models.ApplicationUser>(new UserStore<NetCafeWeb.Models.ApplicationUser>(context));
            ApplicationUser aspSelectedUser = context.Users.Where(u => u.UserName.Equals((deletedUser.UserName), StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();

            UserManager.DeleteAsync(aspSelectedUser);

            return true;
        }
开发者ID:AnTTSE61258,项目名称:NetCafeWeb,代码行数:22,代码来源:UserController.cs

示例5: DeleteConfirmed

        public async Task<ActionResult> DeleteConfirmed(string id) {

            var roleStore = new RoleStore<IdentityRole>(db);
            var roleManager = new RoleManager<IdentityRole>(roleStore);

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

            if (ModelState.IsValid) {
                if (id == null) {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }

                var user = await userManager.FindByIdAsync(id);
                
                // ev. 3parts inloggningar
                var logins = user.Logins;
                foreach (var login in logins.ToList()) {
                    await userManager.RemoveLoginAsync(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
                }

                var rolesForUser = await userManager.GetRolesAsync(id);

                if (rolesForUser.Count() > 0) {
                    foreach (var item in rolesForUser.ToList()) {
                        // item should be the name of the role
                        var result = await userManager.RemoveFromRoleAsync(user.Id, item);
                    }
                }

                if (user.Documents.Count() > 0) {
                    foreach (var doc in user.Documents.ToList()) {
                        db.Documents.Remove(doc);
                    }
                }

                await userManager.DeleteAsync(user);

                return RedirectToAction("Index");
            }
            else {
                return View();
            }
        }
开发者ID:StaffanE,项目名称:LexiconLMS,代码行数:44,代码来源:UsersController.cs

示例6: DeleteEmployee

 //delete employee
 public void DeleteEmployee(string email)
 {
     var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
     var user = manager.FindByEmail(email);
     if (user != null) {
         DeleteAllEmployeeShifts(email);
         manager.DeleteAsync(user);
     };
     UserManagerExtensions.Delete(manager, user);
     _repo.SaveChanges();
 }
开发者ID:GBoh,项目名称:Shiftr,代码行数:12,代码来源:ShiftService.cs

示例7: Seed

        private async Task Seed(IUnitOfWork uow  , UserManager<ApplicationUser> usrMan, RoleManager<IdentityRole> _RoleManager)
        {

            var email = "[email protected]";
            var RoleName = "CustomerAdmin";
            var role = await _RoleManager.FindByNameAsync(RoleName);
            if (role == null)
            {
                role = new IdentityRole { Name = RoleName };
                await _RoleManager.CreateAsync(role);
            }

        RoleName = "superadmin";
            role = await _RoleManager.FindByNameAsync( RoleName );
            if ( role == null)
            {
                role = new IdentityRole { Name = "SuperAdmin" };
                await _RoleManager.CreateAsync(role);
            }
            
            var appUser = await usrMan.FindByEmailAsync(email);
            if (appUser != null)
            {
                var result = await usrMan.DeleteAsync(appUser);
            }
            else 
            {
                appUser = new ApplicationUser() { UserName = email, Email = email };
                var result2 = await usrMan.CreateAsync(appUser, "Shafiro2,");
                if (result2.Succeeded)
                {
                    await usrMan.AddToRoleAsync(appUser,  RoleName ); 
                    var hrmUser = new User()
                    {
                        UserID = "7310209296",
                        FirstName = "Gabriel",
                        LastName = "Tekin",
                        UserName = "gabtek",
                        UserCode = "tekgab",
                        PhoneNumber = "0702385537"
                    };
                    if (uow.UserRepository.GetEagerLoad( w => w.UserID.Equals( hrmUser.UserID, StringComparison.OrdinalIgnoreCase )).FirstOrDefault()   == null )
                    {
                        uow.UserRepository.Insert(hrmUser);
                        uow.Save();
                    }
                    
                }
                else
                {
                    var code = result2.Errors.FirstOrDefault().Code;
                }
            }

            } // method seed 
开发者ID:gomaltao,项目名称:HRM,代码行数:55,代码来源:Startup.cs


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