/// <summary> /// Removes an User from the list of users in this Financial Institution /// </summary> /// <param name="user">User to be removed</param> public virtual void RemoveFinancialUser(FinancialUser user) { FinancialUsers.Remove (user); }
/// <summary> /// Creates a new Financial User in the system /// </summary> /// <param name="financialInstitution">Financial Institution this user belongs to.</param> /// <param name="username">Username creating user</param> /// <param name="financialUser">Financial User to be created</param> /// <param name="applicationRoles">Application roles to be assigned to the financial user</param> public void CreateNewFinancialUser(string financialInstitutionName, string username, FinancialUser financialUser, IList<int> applicationRolesIds) { try { IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO (); IApplicationRoleDAO applicationRoleDAO = _daoFactory.GetApplicationRoleDAO (); //Make sure it does not exist in the system if (financialInstitutionDAO.FinancialUserExists (financialInstitutionName, financialUser.Username)) { throw new ZiblerBusinessComponentsException ( Resources.FinancialUserOperationsMsgFinancialUserExists); } //Get all the application roles. //TODO: There are not too many application roles, however this may cause issues // in future releases when application roles are defined by the financial institution IList<ApplicationRole> applicationRoles = applicationRoleDAO.FindAll (); //Hash the password. Encryption.EncryptProperties (financialUser); //Add the roles since we did not throw any exception foreach (ApplicationRole applicationRole in applicationRoles) { if (applicationRolesIds.Contains (applicationRole.Id)) financialUser.AddApplicationRole (applicationRole); } //Add the user to the financial institution FinancialInstitution financialInstitution = financialInstitutionDAO.GetFinancialInstitutionByName ( financialInstitutionName); /* If we could not find the financial institution * raise an exception */ if (financialInstitution == null) { throw new ZiblerBusinessComponentsUnknownException (); } else { financialInstitution.AddFinancialUser (financialUser); financialInstitutionDAO.MakePersistent (financialInstitution); } } /* If the exception was thrown here, just pass it up */ catch (ZiblerBusinessComponentsException ex) { throw; } /* Catch any Data Layer or other exception and throw an unkown exception */ catch (Exception ex) { ZiblerBusinessComponentsUnknownException exc = new ZiblerBusinessComponentsUnknownException (ex); /* Throw the new exception */ throw exc; } }
/// <summary> /// Adds a new User to the list of users in this Financial Institution /// </summary> /// <param name="user">User to be added</param> public virtual void AddFinancialUser(FinancialUser user) { user.FinancialInstitution = this; FinancialUsers.Add (user); }
/// <summary> /// Update the FinancialUser and save it to the system /// </summary> /// <param name="financialUserToUpdate">FinancialUser to be updated</param> /// <param name="applicationRoleIds">List of application roles to be associated to this financial User</param> /// <exception cref="ZiblerBusinessComponentsException" /> public void UpdateFinancialUser(FinancialUser financialUserToUpdate, IList<int> applicationRoleIds) { try { IFinancialInstitutionDAO financialInstitutionDAO = _daoFactory.GetFinancialInstitutionDAO (); IFinancialUserDAO financialUserDAO = _daoFactory.GetFinancialUserDAO (); IApplicationRoleDAO applicationRoleDAO = _daoFactory.GetApplicationRoleDAO (); string oldUserName = financialUserDAO.GetFinancialUserUsername ( financialUserToUpdate.Id); string oldPassword = financialUserDAO.GetFinancialUserPassword ( financialUserToUpdate.Id); int numberOfAdministradores = financialUserDAO.GetTotalOfAdministradores ( financialUserToUpdate.FinancialInstitution.Name); //Variables used to verify the user must have at least one specific role bool mustBeAdministrador = false; if (oldUserName == "") throw new ZiblerBusinessComponentsException (Resources.RecordNotFound); //Verify the minimum number of Aministradores users. if (numberOfAdministradores <= MIN_NUMBER_ADMINISTRADORES) { //Get all the available application roles. Note that these are not FinancialInstitution specific. //TODO: Perhaps in the future these should be financial institution specific. foreach (ApplicationRole role in financialUserToUpdate.ApplicationRoles) { if (role.Name == "Administrador") { mustBeAdministrador = true; break; } } } //Determine if we should check for the user name. bool checkForUserName = true; if (oldUserName == financialUserToUpdate.Username) checkForUserName = false; //If the user name has been changed, then we verified that the new one //is not already in the system. if (checkForUserName) { if (financialInstitutionDAO.FinancialUserExists ( financialUserToUpdate.FinancialInstitution.Name, financialUserToUpdate.Username)) { throw new ZiblerBusinessComponentsException ( Resources.FinancialUserOperationsMsgFinancialUserExists); } } //Remove all and just read the ones that should be associated. financialUserToUpdate.ApplicationRoles.Clear (); //Get all the application roles. //TODO: There are not too many application roles, however this may cause issues // in future releases when application roles are defined by the financial institution IList<ApplicationRole> applicationRoles = applicationRoleDAO.FindAll (); //Before we proceed to associate the application role to the user, we verify //if there should be administrator/autorizador in the list of selected Ids if (mustBeAdministrador) { bool administradorFound = false; foreach (int applicationRoleId in applicationRoleIds) { foreach (ApplicationRole role in applicationRoles) { if (role.Id == applicationRoleId) { if (role.Name == "Administrador") administradorFound = true; } } } if (mustBeAdministrador) { if (!administradorFound) { throw new ZiblerBusinessComponentsException ( Resources.FinancialUserOperationsMsgFinancialUserNeedsAtLeastOneAdministradorAutorizador); } } } /* If the old password is different, it means they changed it, so * go ahead and encrypt the new password, otherwise don't do anything */ if (oldPassword != financialUserToUpdate.UserPassword) { //Hash the password. Encryption.EncryptProperties (financialUserToUpdate); } //Add the roles since we did not throw any exception foreach (ApplicationRole applicationRole in applicationRoles) { if (applicationRoleIds.Contains (applicationRole.Id)) financialUserToUpdate.AddApplicationRole (applicationRole); } financialUserDAO.MakePersistent (financialUserToUpdate); } /* If the exception was thrown here, just pass it up */ catch (ZiblerBusinessComponentsException ex) { throw; } /* Catch any Data Layer or other exception and throw an unkown exception */ catch (Exception ex) { ZiblerBusinessComponentsUnknownException exc = new ZiblerBusinessComponentsUnknownException (ex); /* Throw the new exception */ throw exc; } }