/// <summary>Creates a new, empty RoleAuditActionEntity object.</summary> /// <returns>A new, empty RoleAuditActionEntity object.</returns> public override IEntity Create() { IEntity toReturn = new RoleAuditActionEntity(); // __LLBLGENPRO_USER_CODE_REGION_START CreateNewRoleAuditAction // __LLBLGENPRO_USER_CODE_REGION_END return(toReturn); }
/// <summary> /// Saves the audit actions for role specified. First removes all present rows for the roleid /// </summary> /// <param name="auditActionIDs">Audit action IDs.</param> /// <param name="roleID">Role ID.</param> /// <returns>true if the save action succeeded, false otherwise</returns> public static bool SaveAuditActionsForRole(List <int> auditActionIDs, int roleID) { RoleAuditActionCollection roleAuditActions = new RoleAuditActionCollection(); Transaction trans = new Transaction(IsolationLevel.ReadCommitted, "SaveAuditActionsForRole"); // add this collection to the transaction so all actions executed through this collection will be inside the transaction trans.Add(roleAuditActions); try { // first remove the existing rows for the role roleAuditActions.DeleteMulti((RoleAuditActionFields.RoleID == roleID)); // THEN add new ones to the same collection. foreach (int auditActionID in auditActionIDs) { RoleAuditActionEntity newRoleAuditAction = new RoleAuditActionEntity(); newRoleAuditAction.AuditActionID = auditActionID; newRoleAuditAction.RoleID = roleID; roleAuditActions.Add(newRoleAuditAction); } // save all new entities roleAuditActions.SaveMulti(); // succeeded, commit transaction trans.Commit(); return(true); } catch { // failed, rollback transaction trans.Rollback(); throw; } finally { trans.Dispose(); } }