public static int Create(int IssueId, string EMail) { EMailIssueExternalRecipientRow newRow = new EMailIssueExternalRecipientRow(); newRow.IssueId = IssueId; newRow.EMail = EMail; newRow.Update(); return newRow.PrimaryKeyId; }
/// <summary> /// Updates the specified recipient. /// </summary> /// <param name="recipient">The recipient.</param> public static void Update(int IssueId, Hashtable recipientHash) { if(!Incident.CanUpdateExternalRecipients(IssueId)) throw new AccessDeniedException(); using(DbTransaction tran = DbTransaction.Begin()) { EMailIssueExternalRecipientRow[] list = EMailIssueExternalRecipientRow.List(IssueId); Hashtable alreadyAddedItems = new Hashtable(); foreach(EMailIssueExternalRecipientRow row in list) { if(!alreadyAddedItems.ContainsKey(row.EMail.ToLower())) alreadyAddedItems.Add(row.EMail.ToLower(),null); } // Delete foreach(EMailIssueExternalRecipientRow row in list) { if(!recipientHash.ContainsKey(row.EMailIssueExternalRecipientId)) { alreadyAddedItems.Remove(row.EMail.ToLower()); row.Delete(); } } // Insert foreach(int Key in recipientHash.Keys) { string Value = (string)recipientHash[Key]; if(Key<0 && !alreadyAddedItems.ContainsKey(Value.ToLower())) { EMailIssueExternalRecipientRow newRow = new EMailIssueExternalRecipientRow(); newRow.IssueId = IssueId; newRow.EMail = Value; newRow.Update(); alreadyAddedItems.Add(Value.ToLower(),null); } } tran.Commit(); } }