/// <summary> /// Adds a Partner to an Extract, if they are not already present /// </summary> /// <param name="APartnerKey">PartnerKey of Partner</param> /// <param name="ALocationPK">Location PK of a Partner's PartnerLocation /// (usually the LocationPK of the 'Best Address' of the Partner).</param> /// <param name="AExtractId">ExtractId of the Extract that the Partner should /// get added to.</param> /// <returns>True if the Partner was added to the Extract, otherwise false.</returns> public static bool AddPartnerToExtract(Int64 APartnerKey, TLocationPK ALocationPK, int AExtractId) { TDBTransaction Transaction = null; bool SubmissionOK = false; MExtractTable TemplateTable; MExtractRow TemplateRow; MExtractRow NewRow; if (APartnerKey > 0) { DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { /* * First check whether the Partner isn't already in that Extract */ TemplateTable = new MExtractTable(); TemplateRow = TemplateTable.NewRowTyped(false); TemplateRow.ExtractId = AExtractId; TemplateRow.PartnerKey = APartnerKey; if (MExtractAccess.CountUsingTemplate(TemplateRow, null, Transaction) == 0) { /* * Add Partner to Extract. */ NewRow = TemplateTable.NewRowTyped(false); NewRow.ExtractId = AExtractId; NewRow.PartnerKey = APartnerKey; NewRow.SiteKey = ALocationPK.SiteKey; NewRow.LocationKey = ALocationPK.LocationKey; TemplateTable.Rows.Add(NewRow); MExtractAccess.SubmitChanges(TemplateTable, Transaction); SubmissionOK = true; } else { // Partner is already in that Extract -> Partner does not get added. SubmissionOK = false; } }); } else { // Invalid PartnerKey -> return false; SubmissionOK = false; } return(SubmissionOK); }
/// <summary> /// Adds a Partner to an Extract, if they are not already present /// </summary> /// <param name="APartnerKey">PartnerKey of Partner</param> /// <param name="ALocationPK">Location PK of a Partner's PartnerLocation /// (usually the LocationPK of the 'Best Address' of the Partner).</param> /// <param name="AExtractId">ExtractId of the Extract that the Partner should /// get added to.</param> /// <returns>True if the Partner was added to the Extract, otherwise false.</returns> public static bool AddPartnerToExtract(Int64 APartnerKey, TLocationPK ALocationPK, int AExtractId) { bool ReturnValue; TDBTransaction WriteTransaction; MExtractTable TemplateTable; MExtractRow TemplateRow; MExtractRow NewRow; Boolean NewTransaction; if (APartnerKey > 0) { WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { /* * First check whether the Partner isn't already in that Extract */ TemplateTable = new MExtractTable(); TemplateRow = TemplateTable.NewRowTyped(false); TemplateRow.ExtractId = AExtractId; TemplateRow.PartnerKey = APartnerKey; if (MExtractAccess.CountUsingTemplate(TemplateRow, null, WriteTransaction) == 0) { /* * Add Partner to Extract. */ NewRow = TemplateTable.NewRowTyped(false); NewRow.ExtractId = AExtractId; NewRow.PartnerKey = APartnerKey; NewRow.SiteKey = ALocationPK.SiteKey; NewRow.LocationKey = ALocationPK.LocationKey; TemplateTable.Rows.Add(NewRow); MExtractAccess.SubmitChanges(TemplateTable, WriteTransaction); ReturnValue = true; } else { // Partner is already in that Extract -> Partner does not get added. ReturnValue = false; } if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TExtractsHandling.AddPartnerToExtract: committed own transaction!"); } } catch (Exception Exc) { TLogging.Log("An Exception occured while adding a Partner to an Extract:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } } else { // Invalid PartnerKey -> return false; ReturnValue = false; } return(ReturnValue); }