public static bool RegisterChanges( List <string> JsonChanges, List <string> NeededChanges ) { foreach (string PreCheck in JsonChanges) { DataHistoryChange PreCheckObj = JsonConvert.DeserializeObject <DataHistoryChange>(PreCheck); if (NeededChanges.Contains(PreCheckObj.Type)) { NeededChanges.Remove(PreCheckObj.Type); } } if (NeededChanges.Count != 0) { return(false); } // data is comming like this: ["{}", "{}"] foreach (string JsonObjectString in JsonChanges) { DataHistoryChange ChangeObject = JsonConvert.DeserializeObject <DataHistoryChange>(JsonObjectString); DataConsentTDS Set = new DataConsentTDS(); // generate and add new row for p_consent_history PConsentHistoryRow NewRow = Set.PConsentHistory.NewRowTyped(); NewRow.EntryId = -1; NewRow.PartnerKey = ChangeObject.PartnerKey; NewRow.Type = ChangeObject.Type; NewRow.Value = ChangeObject.Value; NewRow.ConsentDate = ChangeObject.ConsentDate; NewRow.ChannelCode = ChangeObject.ChannelCode; Set.PConsentHistory.Rows.Add(NewRow); // generate and add each row for a allowed purpose in p_consent_history_permission foreach (string AllowedPuroseCode in ChangeObject.Permissions.Split(',')) { if (AllowedPuroseCode.Trim().Equals("")) { continue; } // catch non permission values PConsentHistoryPermissionRow NewPermRow = Set.PConsentHistoryPermission.NewRowTyped(); NewPermRow.PurposeCode = AllowedPuroseCode; NewPermRow.ConsentHistoryEntry = -1; Set.PConsentHistoryPermission.Rows.Add(NewPermRow); } DataConsentTDSAccess.SubmitChanges(Set); } return(true); }
public static DataConsentTDS GetConsentChannelAndPurpose() { TDBTransaction T = new TDBTransaction(); TDataBase DB = DBAccess.Connect("Get Consent Channel + Purpose"); DataConsentTDS Set = new DataConsentTDS(); DB.ReadTransaction(ref T, delegate { PConsentChannelAccess.LoadAll(Set, T); PPurposeAccess.LoadAll(Set, T); }); return(Set); }
public static bool EditHistory( Int64 APartnerKey, string ADataType, string AChannelCode, DateTime AConsentDate, string AConsentCodes, out TVerificationResultCollection AVerificationResult ) { AVerificationResult = new TVerificationResultCollection(); DataConsentTDS LastEntry = LastKnownEntry(APartnerKey, ADataType); DataConsentTDSPConsentHistoryRow LastEntryRow = LastEntry.PConsentHistory[0]; // tried to save with same permissions, we skip these actions and throw a error if (LastEntryRow.AllowedPurposes == AConsentCodes && LastEntryRow.ConsentDate == AConsentDate && LastEntryRow.ChannelCode == AChannelCode) { AVerificationResult.Add(new TVerificationResult("error", "no_changes", TResultSeverity.Resv_Critical)); return(false); } DataHistoryChange ToChange = new DataHistoryChange { ConsentDate = AConsentDate, ChannelCode = AChannelCode, PartnerKey = APartnerKey, Type = ADataType, Value = LastEntryRow.Value, Permissions = AConsentCodes }; String ToRegister = JsonConvert.SerializeObject(ToChange); List <string> JsonList = new List <string> { ToRegister }; RegisterChanges(JsonList, new List <string>() { ADataType }); return(true); }
public static DataConsentTDS LastKnownEntry( Int64 APartnerKey, string ADataType ) { TDBTransaction T = new TDBTransaction(); TDataBase DB = DBAccess.Connect("Get Last known entry"); DataConsentTDS Set = new DataConsentTDS(); List <OdbcParameter> SQLParameter = new List <OdbcParameter>(); DB.ReadTransaction(ref T, delegate { string sql = "SELECT " + "`p_data_history`.*, " + "GROUP_CONCAT(`p_data_history_permission`.`p_purpose_code_c` SEPARATOR ',') AS `AllowedPurposes` " + "FROM `p_data_history` " + "LEFT JOIN `p_data_history_permission` " + "ON `p_data_history`.`p_entry_id_i` = `p_data_history_permission`.`p_data_history_entry_i` " + "WHERE `p_data_history`.`p_partner_key_n` = ? " + "AND `p_data_history`.`p_type_c` = ? " + "GROUP BY `p_data_history`.`p_entry_id_i` " + "ORDER BY `p_data_history`.`p_entry_id_i` DESC " + "LIMIT 1"; SQLParameter.Add(new OdbcParameter("PartnerKey", OdbcType.VarChar) { Value = APartnerKey.ToString() }); SQLParameter.Add(new OdbcParameter("DataType", OdbcType.VarChar) { Value = ADataType }); // DB.SelectDT(Set, sql, T, SQLParameter.ToArray(), 0,0); DB.SelectDT(Set.PDataHistory, sql, T, SQLParameter.ToArray()); PConsentChannelAccess.LoadAll(Set, T); PPurposeAccess.LoadAll(Set, T); }); return(Set); }
public static DataConsentTDS GetHistory( Int64 APartnerKey, string ADataType ) { TDBTransaction T = new TDBTransaction(); TDataBase DB = DBAccess.Connect("Get data history for partner"); DataConsentTDS Set = new DataConsentTDS(); List <OdbcParameter> SQLParameter = new List <OdbcParameter>(); DB.ReadTransaction(ref T, delegate { // prepare for one huge cunk sql string sql = "" + "SELECT " + " `pdh`.*, " + " GROUP_CONCAT(`pdhp`.`p_purpose_code_c` SEPARATOR ',') AS `AllowedPurposes` " + "FROM `p_data_history` AS `pdh` " + "LEFT JOIN `p_data_history_permission` AS `pdhp` " + " ON `pdh`.`p_entry_id_i` = `pdhp`.`p_data_history_entry_i` " + "WHERE `pdh`.`p_partner_key_n` = ? " + " AND `pdh`.`p_type_c` = ? " + "GROUP BY `pdh`.`p_entry_id_i` " + "ORDER BY `pdh`.`p_entry_id_i` DESC"; SQLParameter.Add(new OdbcParameter("PartnerKey", OdbcType.BigInt) { Value = APartnerKey.ToString() }); SQLParameter.Add(new OdbcParameter("DataType", OdbcType.VarChar) { Value = ADataType }); Set.PDataHistory.Constraints.Clear(); //mmmm... DB.SelectDT(Set.PDataHistory, sql, T, SQLParameter.ToArray()); PConsentChannelAccess.LoadAll(Set, T); PPurposeAccess.LoadAll(Set, T); }); return(Set); }
public static DataConsentTDS LastKnownEntry( Int64 APartnerKey, string ADataType ) { TDBTransaction T = new TDBTransaction(); TDataBase DB = DBAccess.Connect("Get Last known entry"); DataConsentTDS Set = new DataConsentTDS(); List <OdbcParameter> SQLParameter = new List <OdbcParameter>(); DB.ReadTransaction(ref T, delegate { string sql = "SELECT " + "`p_consent_history`.*, " + "GROUP_CONCAT(`p_consent_history_permission`.`p_purpose_code_c` SEPARATOR ',') AS `AllowedPurposes` " + "FROM `p_consent_history` " + "LEFT JOIN `p_consent_history_permission` " + "ON `p_consent_history`.`p_entry_id_i` = `p_consent_history_permission`.`p_consent_history_entry_i` " + "WHERE `p_consent_history`.`p_partner_key_n` = ? " + "AND `p_consent_history`.`p_type_c` = ? " + "GROUP BY `p_consent_history`.`p_entry_id_i` " + "ORDER BY `p_consent_history`.`p_entry_id_i` DESC " + "LIMIT 1"; SQLParameter.Add(new OdbcParameter("PartnerKey", OdbcType.BigInt) { Value = APartnerKey }); SQLParameter.Add(new OdbcParameter("DataType", OdbcType.VarChar) { Value = ADataType }); DB.SelectDT(Set.PConsentHistory, sql, T, SQLParameter.ToArray()); if (Set.PConsentHistory.Count == 0) { // there is no consent yet // do we have a value at all? List <string> Subscriptions; List <string> PartnerTypes; string DefaultEmailAddress; string DefaultPhoneMobile; string DefaultPhoneLandline; PartnerEditTDS PartnerDS = TSimplePartnerEditWebConnector.GetPartnerDetails(APartnerKey, out Subscriptions, out PartnerTypes, out DefaultEmailAddress, out DefaultPhoneMobile, out DefaultPhoneLandline); if (ADataType == MPartnerConstants.CONSENT_TYPE_ADDRESS) { // what about new contact? PLocationRow locationRow = null; if (PartnerDS.PLocation.Rows.Count > 0) { locationRow = PartnerDS.PLocation[0]; } else { locationRow = PartnerDS.PLocation.NewRowTyped(); } PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped(); row.EntryId = -1; row.PartnerKey = APartnerKey; row.Type = ADataType; row.Value = locationRow.StreetName + ", " + locationRow.PostalCode + " " + locationRow.City + ", " + locationRow.CountryCode; row.ConsentDate = DateTime.Today; Set.PConsentHistory.Rows.Add(row); } if (ADataType == MPartnerConstants.CONSENT_TYPE_EMAIL) { PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped(); row.EntryId = -1; row.PartnerKey = APartnerKey; row.Type = ADataType; row.Value = DefaultEmailAddress; row.ConsentDate = DateTime.Today; Set.PConsentHistory.Rows.Add(row); } if (ADataType == MPartnerConstants.CONSENT_TYPE_LANDLINE) { PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped(); row.EntryId = -1; row.PartnerKey = APartnerKey; row.Type = ADataType; row.Value = DefaultPhoneLandline; row.ConsentDate = DateTime.Today; Set.PConsentHistory.Rows.Add(row); } if (ADataType == MPartnerConstants.CONSENT_TYPE_MOBILE) { PConsentHistoryRow row = Set.PConsentHistory.NewRowTyped(); row.EntryId = -1; row.PartnerKey = APartnerKey; row.Type = ADataType; row.Value = DefaultPhoneMobile; row.ConsentDate = DateTime.Today; Set.PConsentHistory.Rows.Add(row); } } PConsentChannelAccess.LoadAll(Set, T); PConsentPurposeAccess.LoadAll(Set, T); }); return(Set); }