本文整理汇总了C#中UserManager.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# UserManager.Delete方法的具体用法?C# UserManager.Delete怎么用?C# UserManager.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserManager
的用法示例。
在下文中一共展示了UserManager.Delete方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveUser
internal bool RemoveUser(string username)
{
Models.ApplicationDbContext context = new Models.ApplicationDbContext();
var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
userMgr.Delete(userMgr.FindByName(username));
return true;
}
示例2: Delete
public void Delete(ApplicationUser user)
{
var userStore = new UserStore<ApplicationUser>(this.Context);
var userManager = new UserManager<ApplicationUser>(userStore);
userManager.Delete(user);
var context = userStore.Context;
context.SaveChanges();
}
示例3: grvUsers_RowDeleting
protected void grvUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
var id = grvUsers.DataKeys[e.RowIndex].Value.ToString();
var userStore = new UserStore<IdentityUser>();
var userManager = new UserManager<IdentityUser>(userStore);
var user = userManager.FindById(id);
if (user != null && user.UserName != "Admin")
{
userManager.Delete(user);
}
if (id == SharedClass.CurrentUser)
{
Response.Redirect("~/Login.aspx?Logout=true");
}
}
示例4: CleanUp
private void CleanUp(IdentityUser user, UserManager<IdentityUser, Guid> manager)
{
var result = manager.Delete(user);
if (!result.Succeeded)
throw new Exception("Failed to delete Identity");
}
示例5: DeleteUser
public bool DeleteUser(string id)
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var user = manager.FindById(id);
var success=manager.Delete(user);
if(success.Succeeded)
return true;
return false;
}
示例6: PostEmployee
public IHttpActionResult PostEmployee(Employee employee)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var userStore = new UserStore<IdentityUser>();
var manager = new UserManager<IdentityUser>(userStore);
var user = new IdentityUser() { UserName = employee.Email, Email = employee.Email, PhoneNumber = employee.PrimaryMobile.ToString() };
// TODO Environment Varialbe
IdentityResult result = manager.Create(user, WebConfigurationManager.AppSettings["DefaultPassword"]);
// IdentityResult result = manager.Create(user, Environment.GetEnvironmentVariable("DefaultPassword"));
string[] roles = { "", "", "", "", "ClientEmployee", "ClientAdmin", "OrgEmployee", "OrgManager", "SecondLevelManager" };
int roleIndex = employee.EmpStatus;
if (result.Succeeded)
{
employee.AuthUserId = user.Id;
employee.ProfilePic = "0";
employee.EmpStatus = 1;
db.Employees.Add(employee);
if (db.SaveChanges() != 1)
{
manager.Delete(user);
}
else
{
//manager.AddToRole(employee.AuthUserId, "ClientEmployee");
manager.AddToRole(employee.AuthUserId, roles[roleIndex]);
}
}
return CreatedAtRoute("DefaultApi", new { id = employee.EmpId }, employee);
}
示例7: deleteUser
public ActionResult deleteUser(string userID)
{
ajaxReturnData data = new ajaxReturnData();
try
{
using (ApplicationDbContext DB = new ApplicationDbContext())
{
ApplicationUser user = new ApplicationUser();
var store = new UserStore<ApplicationUser>(DB);
UserManager<ApplicationUser> um = new UserManager<ApplicationUser>(store);
user = um.FindById(userID);
if (user.UserName == "[email protected]")
{
data.statusCode = (int)statusCodes.fail;
data.message = "I'm sorry Dave, I'm afraid I can't do that";
}
else {
DB.UserLanguages.RemoveRange(DB.UserLanguages.Where(x => x.userID == userID));
data.message = "User '" + user.UserName + "' has become one with the void";
um.Delete(user);
data.statusCode = (int)statusCodes.successRun;
}
}
}
catch (Exception ex)
{
data.statusCode = (int)statusCodes.fail;
data.message = "Failed to delete user; Error is: " + ex.Message;
}
return Json(data);
}
示例8: KullaniciSil
public ActionResult KullaniciSil(string id)
{
UserStore<HaberUser> userStore = new UserStore<HaberUser>(context);
userManager = new UserManager<HaberUser>(userStore);
if (id==null || id=="")
{
return RedirectToAction("KullaniciListesi");
}
else
{
var user = userManager.FindByName(id.Trim());
if (user!=null)
{
userManager.Delete(user);
context.SaveChanges();
}
return RedirectToAction("KullaniciListesi");
}
}
示例9: TenantDelete
public JsonResult TenantDelete(string TenantID)
{
var BID = db.Tenant.Where(c => c.ID == TenantID).FirstOrDefault().Apartment.Buildings.ID;
var AID = db.Tenant.Where(c => c.ID == TenantID).FirstOrDefault().Apartment.ID;
try {
ApplicationDbContext context = new ApplicationDbContext();
ApplicationUser AppUser = new ApplicationUser();
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
// remove tenant from role
userManager.RemoveFromRole(TenantID, "Tenant");
//find tenant on the tenant table
AspNetUsers aspnetuser = db.AspNetUsers.Find(TenantID);
db.AspNetUsers.Remove(aspnetuser);
var tn = db.Tenant.Find(TenantID);
//remove tenant from the tenant table
db.Tenant.Remove(tn);
//save changes
db.SaveChanges();
//load tenant applicationuser
AppUser = userManager.FindById(TenantID);
//delete tenant applicationuser
var result = userManager.Delete(AppUser);
}
catch (Exception e)
{
ViewBag.Message = e.Message;
}
var tenants = db.Tenant.Where(c => c.aptID == (int?)AID).Select(c => new
{
ID = c.ID,
FirstName = c.FirstName,
LastName = c.LastName,
Phone = c.Phone,
UserName = c.Username,
CreatedDate = c.Created
}).ToList();
var mydata = Json(tenants);
return new JsonResult { Data = mydata, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
示例10: removeSSAEktronMember
public void removeSSAEktronMember(string UserPIN)
{
try
{
UserManager Usermanager = new UserManager();
UserCriteria criteria = new UserCriteria(UserProperty.UserName, EkEnumeration.OrderByDirection.Ascending);
criteria.AddFilter(UserProperty.UserName, CriteriaFilterOperator.EqualTo, UserPIN);
List<UserData> UserList = Usermanager.GetList(criteria);
long EktronUserID = UserList[0].Id;
if (Ektron.Cms.Framework.Context.UserContextService.Current.IsLoggedIn)
{
Usermanager.Delete(EktronUserID);
// add user to group MSBA Members
//UserGroupManager UserGroupmanager = new UserGroupManager();
//Add a User to a UserGroup
// UserGroupmanager.DeleteUser(1, newUserdata.Id);
}
}
catch { }
}