public Transaction GetCreationDetails(int CaseId, int ListingId)
        {
            Transaction t = new Transaction();

            DataProvider.ExecuteCmd(GetConnection, "dbo.TransactionsCreateInfo_SelectByListingAndCaseId"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@CaseId", CaseId);
                paramCollection.AddWithValue("@ListingId", ListingId);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                switch (set)
                {
                case 0:
                    PersonBase buyer = MapBuyer(reader);
                    if (t.Buyers == null)
                    {
                        t.Buyers = new List <PersonBase>();
                    }
                    t.Buyers.Add(buyer);
                    break;

                case 1:
                    PersonBase buyerAgent = MapBuyerAgent(reader);
                    if (t.BuyerAgents == null)
                    {
                        t.BuyerAgents = new List <PersonBase>();
                    }
                    t.BuyerAgents.Add(buyerAgent);
                    break;

                case 2:
                    TransactionDetails listing = MapTransactionDetails(reader);
                    t.ListingDetails           = listing;
                    break;

                case 3:
                    ListingAgentInfo listingAgent = MapListingAgentInfo(reader);
                    t.ListingAgent = listingAgent;
                    break;
                }
            }
                                    );
            return(t);
        }
        public static ListingAgentInfo MapListingAgentInfo(IDataReader reader)
        {
            int index = 0;
            ListingAgentInfo ListingAgent = new ListingAgentInfo();

            ListingAgent.BuyerAgencyCompensation = reader.GetSafeDouble(index++);
            ListingAgent.Contingency             = reader.GetSafeString(index++);
            ListingAgent.Disclosures             = reader.GetSafeString(index++);
            ListingAgent.ListAgentCellPhone      = reader.GetSafeString(index++);
            ListingAgent.ListAgentDirectPhone    = reader.GetSafeString(index++);
            ListingAgent.ListAgentEmail          = reader.GetSafeString(index++);
            ListingAgent.ListOfficePhone         = reader.GetSafeString(index++);
            ListingAgent.LockBoxLocation         = reader.GetSafeString(index++);
            ListingAgent.OccupantType            = reader.GetSafeString(index++);
            ListingAgent.OwnerName           = reader.GetSafeString(index++);
            ListingAgent.PrivateRemarks      = reader.GetSafeString(index++);
            ListingAgent.ShowingContactName  = reader.GetSafeString(index++);
            ListingAgent.ShowingContactPhone = reader.GetSafeString(index++);
            ListingAgent.ShowingContactType  = reader.GetSafeString(index++);
            ListingAgent.ShowingInstructions = reader.GetSafeString(index++);
            return(ListingAgent);
        }
        public Transaction GetById(int id)
        {
            DocumentsService            _documentsService = new DocumentsService();
            Transaction                 t = null;
            Dictionary <int, Milestone> milestoneDictionary = null;
            Dictionary <int, TaskBase>  taskDictionary      = null;
            Dictionary <int, Chat>      chatDictionary      = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Transactions_SelectById"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                switch (set)
                {
                case 0:
                    t = mapTransaction(reader);
                    break;

                case 1:
                    int transactionId = 0;
                    Milestone m       = MilestonesService.MapMilestone(reader, out transactionId);
                    if (t.Milestones == null)
                    {
                        t.Milestones = new List <Milestone>();
                    }
                    t.Milestones.Add(m);
                    if (milestoneDictionary == null)
                    {
                        milestoneDictionary = new Dictionary <int, Milestone>();
                    }
                    milestoneDictionary.Add(m.Id, m);
                    break;

                case 2:
                    int milestoneId           = 0;
                    TaskBase ta               = TasksService.MapTask(reader, out milestoneId);
                    Milestone parentMilestone = milestoneDictionary[milestoneId];
                    if (parentMilestone.Tasks == null)
                    {
                        parentMilestone.Tasks = new List <TaskBase>();
                    }
                    parentMilestone.Tasks.Add(ta);
                    if (taskDictionary == null)
                    {
                        taskDictionary = new Dictionary <int, TaskBase>();
                    }
                    taskDictionary.Add(ta.Id, ta);
                    break;

                case 3:
                    int taskId          = 0;
                    Document d          = _documentsService.MapDocument(reader, out taskId);
                    TaskBase parentTask = taskDictionary[taskId];
                    if (parentTask.Documents == null)
                    {
                        parentTask.Documents = new List <Document>();
                    }
                    parentTask.Documents.Add(d);
                    break;

                case 4:
                    ParticipantBase pb = _participantsService.MapParticipantBase(reader);
                    if (t.Participants == null)
                    {
                        t.Participants = new List <ParticipantBase>();
                    }
                    t.Participants.Add(pb);
                    break;

                case 5:
                    RoleBase rb = MapRoleBases(reader);
                    if (t.Roles == null)
                    {
                        t.Roles = new List <RoleBase>();
                    }
                    t.Roles.Add(rb);
                    break;

                case 6:
                    PendingDocument pd = PendingDocumentService.MapPendingDocument(reader);
                    if (t.PendingDocuments == null)
                    {
                        t.PendingDocuments = new List <PendingDocument>();
                    }
                    t.PendingDocuments.Add(pd);
                    break;

                case 7:
                    DocumentType dt = DocumentTypesService.MapDocumentType(reader);
                    if (t.DocumentTypes == null)
                    {
                        t.DocumentTypes = new List <DocumentType>();
                    }
                    t.DocumentTypes.Add(dt);
                    break;

                case 8:
                    int chatTaskId = 0;

                    Chat ch = ChatService.ChatMapper(reader, out chatTaskId);
                    TaskBase chatParentTask = taskDictionary[chatTaskId];
                    if (chatParentTask.Chats == null)
                    {
                        chatParentTask.Chats = new List <Chat>();
                    }
                    chatParentTask.Chats.Add(ch);

                    if (chatDictionary == null)
                    {
                        chatDictionary = new Dictionary <int, Chat>();
                    }
                    chatDictionary.Add(ch.Id, ch);
                    break;

                case 9:
                    int chatId = 0;

                    ChatMessage cm  = ChatService.MessageMapper(reader, out chatId);
                    Chat parentChat = chatDictionary[chatId];
                    if (parentChat.Message == null)
                    {
                        parentChat.Message = new List <ChatMessage>();
                    }
                    parentChat.Message.Add(cm);
                    break;

                case 10:
                    TransactionDetails listingDetails = MapTransactionDetails(reader);
                    t.ListingDetails = listingDetails;
                    break;

                case 11:
                    PersonBase buyer = MapBuyer(reader);
                    if (t.Buyers == null)
                    {
                        t.Buyers = new List <PersonBase>();
                    }
                    t.Buyers.Add(buyer);
                    break;

                case 12:
                    ListingAgentInfo listAgent = MapListingAgentInfo(reader);
                    t.ListingAgent             = listAgent;
                    break;
                }
            }
                                    );
            return(t);
        }