/// <summary> /// Deletes a role. /// </summary> /// <param name="role">Role</param> public async override Task <IdentityResult> DeleteAsync(TRole role) { if (role.IsStatic) { return(CodeZeroIdentityResult.Failed(string.Format(L("CanNotDeleteStaticRole"), role.Name))); } return(await base.DeleteAsync(role)); }
public async override Task <IdentityResult> DeleteAsync(TUser user) { if (user.UserName == CodeZeroUser <TUser> .AdminUserName) { return(CodeZeroIdentityResult.Failed(string.Format(L("CanNotDeleteAdminUser"), CodeZeroUser <TUser> .AdminUserName))); } return(await base.DeleteAsync(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(CodeZeroIdentityResult.Failed(string.Format(L("Identity.DuplicateUserName"), userName))); } user = (await FindByEmailAsync(emailAddress)); if (user != null && user.Id != expectedUserId) { return(CodeZeroIdentityResult.Failed(string.Format(L("Identity.DuplicateEmail"), emailAddress))); } return(IdentityResult.Success); }
public virtual async Task <IdentityResult> CheckDuplicateRoleNameAsync(int?expectedRoleId, string name, string displayName) { var role = await FindByNameAsync(name); if (role != null && role.Id != expectedRoleId) { return(CodeZeroIdentityResult.Failed(string.Format(L("RoleNameIsAlreadyTaken"), name))); } role = await FindByDisplayNameAsync(displayName); if (role != null && role.Id != expectedRoleId) { return(CodeZeroIdentityResult.Failed(string.Format(L("RoleDisplayNameIsAlreadyTaken"), displayName))); } return(IdentityResult.Success); }
public async override Task <IdentityResult> UpdateAsync(TUser user) { var result = await CheckDuplicateUsernameOrEmailAddressAsync(user.Id, user.UserName, user.EmailAddress); if (!result.Succeeded) { return(result); } //Admin user's username can not be changed! if (user.UserName != CodeZeroUser <TUser> .AdminUserName) { if ((await GetOldUserNameAsync(user.Id)) == CodeZeroUser <TUser> .AdminUserName) { return(CodeZeroIdentityResult.Failed(string.Format(L("CanNotRenameAdminUser"), CodeZeroUser <TUser> .AdminUserName))); } } return(await base.UpdateAsync(user)); }