Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }