/// <summary> /// Deletes a role. /// </summary> /// <param name="role">Role</param> public async override Task <IdentityResult> DeleteAsync(TRole role) { if (role.IsStatic) { return(IdentityResultBase.Failed(string.Format(L("CanNotDeleteStaticRole"), role.Name))); } return(await base.DeleteAsync(role)); }
public async override Task <IdentityResult> DeleteAsync(TUser user) { if (user.UserName == CommonFrameUser <TUser> .AdminUserName) { return(IdentityResultBase.Failed(string.Format(L("CanNotDeleteAdminUser"), CommonFrameUser <TUser> .AdminUserName))); } return(await base.DeleteAsync(user)); }
public virtual async Task <IdentityResult> CheckDuplicateRoleNameAsync(int?expectedRoleId, string name, string displayName) { var role = await FindByNameAsync(name); if (role != null && role.Id != expectedRoleId) { return(IdentityResultBase.Failed(string.Format(L("RoleNameIsAlreadyTaken"), name))); } role = await FindByDisplayNameAsync(displayName); if (role != null && role.Id != expectedRoleId) { return(IdentityResultBase.Failed(string.Format(L("RoleDisplayNameIsAlreadyTaken"), displayName))); } return(IdentityResultBase.Success); }
public async override Task <IdentityResult> UpdateAsync(TUser user) { var result = await CheckDuplicateUsernameOrEmailAddressAsync(user.Id, user.UserName, user.EmailAddress); if (!result.Succeeded) { return(result); } var oldUserName = (await GetUserByIdAsync(user.Id)).UserName; if (oldUserName == CommonFrameUser <TUser> .AdminUserName && user.UserName != CommonFrameUser <TUser> .AdminUserName) { return(IdentityResultBase.Failed(string.Format(L("CanNotRenameAdminUser"), CommonFrameUser <TUser> .AdminUserName))); } return(await base.UpdateAsync(user)); }
public virtual async Task <IdentityResult> CheckDuplicateUsernameOrEmailAddressAsync(long?expectedUserId, string userName, string emailAddress) { var user = (await FindByNameAsync(userName)); if (user != null && user.Id != expectedUserId) { return(IdentityResultBase.Failed(string.Format(L("Identity.DuplicateName"), userName))); } if (!string.IsNullOrEmpty(emailAddress)) { user = (await FindByEmailAsync(emailAddress)); if (user != null && user.Id != expectedUserId) { return(IdentityResultBase.Failed(string.Format(L("Identity.DuplicateEmail"), emailAddress))); } } return(IdentityResultBase.Success); }