Exemplo n.º 1
0
        private void CompareGenerateLoanStagesTasks(int FileId, int WorkflowTemplId, List <Table.WorkflowStage> NewWorkflowStageList, ref string err)
        {
            List <Table.LoanStages> LoanStageList = null;

            err = string.Empty;
            // get the existing Loan Stages
            m_da.InitObsoleteLoanStagesTasks(FileId, WorkflowTemplId, ref err);
            LoanStageList = m_da.GetLoanStagesByFileId(FileId, ref err);
            Dictionary <string, int> loanStages = new Dictionary <string, int>();

            foreach (Table.LoanStages ls in LoanStageList)
            {
                try
                {
                    if (ls.SequenceNumber >= 0)
                    {
                        loanStages.Add(ls.StageName, ls.LoanStageId);
                    }
                }
                catch (Exception ex)
                {
                    m_da.DeleteLoanStage(FileId, ls.LoanStageId, ref err);
                }
            }
            foreach (Table.LoanStages ls in LoanStageList)
            {
                try
                {
                    foreach (KeyValuePair <string, int> kv in loanStages)
                    {
                        if (kv.Key.ToUpper() != ls.StageName.ToUpper())
                        {
                            continue;
                        }
                        if (kv.Value == ls.LoanStageId)
                        {
                            break;
                        }
                        m_da.DeleteLoanStage(FileId, ls.LoanStageId, ref err);
                        break;
                    }
                }
                catch (Exception ex)
                {
                }
            }
            LoanStageList.Clear();
            LoanStageList = m_da.GetLoanStagesByFileId(FileId, ref err);
            Table.LoanStages loanStage = null;
            foreach (Table.WorkflowStage ws in NewWorkflowStageList)
            {
                bool completed = false;
                bool found     = false;
                if (LoanStageList != null && LoanStageList.Count > 0)
                {
                    foreach (Table.LoanStages ls in LoanStageList)
                    {
                        loanStage = ls;
                        if (ls == null)
                        {
                            continue;
                        }
                        if (ls.WflStageId == ws.WorkflowStageId || ls.StageName.Trim().ToUpper() == ws.Name.Trim().ToUpper())
                        {
                            if (ws.Delete)
                            {
                                m_da.DeleteLoanStage(FileId, ls.LoanStageId, ref err);
                            }
                            else
                            if (ls.Completed != DateTime.MinValue)
                            {
                                completed = true;
                            }
                            if (ls.TaskCount <= 0)
                            {
                                break;
                            }
                            found = true;
                            break;
                        }
                    }
                }

                if (ws.Delete)
                {
                    continue;
                }
                if (!found)
                {
                    m_da.GenerateLoanTaskByStage(FileId, WorkflowTemplId, ws.WorkflowStageId, ref err);
                    continue;
                }
                // update the LoanStages with the new WflStageid and WflTemplId
                bool stageCompleted = false;
                m_da.ReplaceLoanStageTasks(FileId, loanStage, WorkflowTemplId, ws.WorkflowStageId, out stageCompleted, ref err);
                if (completed)
                {
                    // need to update Point Stage date
                }
            }

            // after comparing clean up
            m_da.CleanupObsoleteLoanStagesTasks(FileId, WorkflowTemplId, ref err);
        }