/// <summary> /// Removes entries from AuthUsers and OrganizationUsers (if exists) tables when a user is deleted from an organization /// </summary> /// <param name="deletedUserAccessIdentifier">Access Identifier of the deleted user.</param> /// <returns>Boolean value to specify whether user has been removed or not.</returns> public bool RemoveUserEntryFromAuthDB(string deletedUserAccessIdentifier, long deletedUserID, Guid OrganizationID) { bool result = false; TopContractsAuthEntities.TopContractsAuthEntities authContext = new TopContractsAuthEntities.TopContractsAuthEntities(); TopContractsAuthEntities.AuthUser efAuthUser = null; // Checks for the existence of this User's email in AuthUsers table. if (AuthUser.CheckAuthUserExistance(deletedUserAccessIdentifier)) { efAuthUser = authContext.AuthUsers.SingleOrDefault(usr => usr.Email == deletedUserAccessIdentifier); if (efAuthUser.OrganizationUsers.Count() > 1) { if (efAuthUser.OrganizationUsers.Any(usr => usr.OrganizationIdentifier == OrganizationID && usr.UserId == efAuthUser.UserId && usr.SystemUserId == deletedUserID)) { // removes this current org user entry from context authContext.OrganizationUsers.Remove(efAuthUser.OrganizationUsers.SingleOrDefault(usr => usr.OrganizationIdentifier == OrganizationID && usr.UserId == efAuthUser.UserId && usr.SystemUserId == deletedUserID)); } } if (efAuthUser.OrganizationUsers.Count() == 1) { authContext.OrganizationUsers.Remove(efAuthUser.OrganizationUsers.SingleOrDefault(usr => usr.OrganizationIdentifier == OrganizationID && usr.UserId == efAuthUser.UserId && usr.SystemUserId == deletedUserID)); // removes auth user entry also authContext.AuthUsers.Remove(efAuthUser); } int rowsAffected = authContext.SaveChanges(); result = rowsAffected > 0; } return result; }
/// <summary> /// Updated the email/username in AuthUsers and OrganizationUsers table for a users record. /// </summary> /// <param name="currentEmail">Current email existing in the Auth database.</param> /// <param name="newEmail">New email to be set in the Auth database.</param> public void UpdateUserEmailInAuthDB(string currentEmail, string newEmail) { TopContractsAuthEntities.TopContractsAuthEntities authContext = new TopContractsAuthEntities.TopContractsAuthEntities(); // Checks for the existence of this User's email in AuthUsers table. if (AuthUser.CheckAuthUserExistance(currentEmail)) { TopContractsAuthEntities.AuthUser efAuthUser = authContext.AuthUsers.SingleOrDefault(usr => usr.Email == currentEmail); efAuthUser.Email = newEmail; authContext.SaveChanges(); } }