public void SaveContactInfo(ref CustomList<ContactInfo> ContactInfoList, ref CustomList<ContactType> ContactTypeList, ref CustomList<ContactTypeChild> ContactTypeChildList, ref CustomList<ContactDetail> lstContactDetail) { ConnectionManager conManager = new ConnectionManager(ConnectionName.HR); Boolean blnTranStarted = false; try { conManager.BeginTransaction(); ReSetSPName(ContactInfoList, ContactTypeList, ContactTypeChildList); Int32 contactID = ContactInfoList[0].ContactID; blnTranStarted = true; if (ContactInfoList[0].IsAdded) { contactID = Convert.ToInt32(conManager.InsertData(blnTranStarted, ContactInfoList)); ContactInfoList[0].ContactID = contactID; } else conManager.SaveDataCollectionThroughCollection(blnTranStarted, ContactInfoList); foreach (ContactType cT in ContactTypeList) { CustomList<ContactType> ContactType_List = new CustomList<ContactType>(); if (cT.IsAdded) { Int32 contactTypeID = 0; ContactType_List.Add(cT); ContactType_List.InsertSpName = "spInsertContactType"; contactTypeID = Convert.ToInt32(conManager.InsertData(blnTranStarted, ContactType_List)); cT.ContactTypeID = contactTypeID; } if (cT.IsModified) { cT.SetModified(); ContactType_List.Add(cT); ContactType_List.UpdateSpName = "spUpdateContactType"; conManager.SaveDataCollectionThroughCollection(blnTranStarted, ContactType_List); } } CustomList<ContactDetail> ContactDetailList = new CustomList<ContactDetail>(); foreach (ContactType cT in ContactTypeList) { if (cT.IsChecked) { ContactDetail contactDetail = new ContactDetail(); contactDetail.ContactTypeID = cT.ContactTypeID; contactDetail.ContactID = contactID; ContactDetailList.Add(contactDetail); } } foreach (ContactDetail cD in lstContactDetail) { ContactDetail obj = ContactDetailList.Find(f => f.ContactTypeID == cD.ContactTypeID); if (obj.IsNotNull()) obj.SetModified(); else { cD.Delete(); ContactDetailList.Add(cD); } } ReSetSPName(ContactDetailList); conManager.SaveDataCollectionThroughCollection(blnTranStarted, ContactDetailList); ContactInfoList.AcceptChanges(); ContactTypeList.AcceptChanges(); ContactTypeChildList.AcceptChanges(); ContactDetailList.AcceptChanges(); conManager.CommitTransaction(); blnTranStarted = false; } catch (Exception Ex) { conManager.RollBack(); throw Ex; } finally { if (conManager.IsNotNull()) { conManager.Dispose(); } } }
public static CustomList<ContactDetail> GetAllContactDetail(Int32 contactID) { ConnectionManager conManager = new ConnectionManager(ConnectionName.HR); CustomList<ContactDetail> ContactDetailCollection = new CustomList<ContactDetail>(); IDataReader reader = null; String sql = "select *from ContactDetail Where ContactID=" + contactID.ToString(); try { conManager.OpenDataReader(sql, out reader); while (reader.Read()) { ContactDetail newContactDetail = new ContactDetail(); newContactDetail.SetData(reader); ContactDetailCollection.Add(newContactDetail); } ContactDetailCollection.InsertSpName = "spInsertContactDetail"; ContactDetailCollection.UpdateSpName = "spUpdateContactDetail"; ContactDetailCollection.DeleteSpName = "spDeleteContactDetail"; return ContactDetailCollection; } catch (Exception ex) { throw (ex); } finally { if (reader != null && !reader.IsClosed) reader.Close(); } }