コード例 #1
0
ファイル: FormServices.cs プロジェクト: andredantass/ProMat
        public List <string> GetNextUserDepartmentLeadDisQualifield()
        {
            List <string>            result                   = new List <string>();
            DepartmentServices       departmentServices       = new DepartmentServices();
            DisQualifiedLeadServices disQualifiedLeadServices = new DisQualifiedLeadServices();
            AttendantServices        attendantServices        = new AttendantServices();

            List <Department> lstDepartments             = departmentServices.GetDepartments();
            DisqualifiedLead  lastDisQualifiedLeadInsert = disQualifiedLeadServices.GetLastDisQualifiedLeadInserted();

            Department nextDepartment = null;

            if (lastDisQualifiedLeadInsert != null)
            {
                nextDepartment = lstDepartments.SkipWhile(x => x.DepartmentId != lastDisQualifiedLeadInsert.DepartmentID).Skip(1).FirstOrDefault();
            }

            if (nextDepartment == null)
            {
                nextDepartment = lstDepartments[0];
            }

            List <Attendant> lstAttendants = attendantServices.GetAttendantsByCompanyId(nextDepartment.DepartmentId);

            DisqualifiedLead lastDisQualifiedLeadInsertAttendant = disQualifiedLeadServices.GetLastDisQualifiedLeadInsertedAttendant(nextDepartment.DepartmentId);

            if (lastDisQualifiedLeadInsertAttendant == null)
            {
                result.Add(nextDepartment.DepartmentId.ToString());
                result.Add(lstAttendants[0].AttendantId.ToString());
                if (nextDepartment.WebHook != null)
                {
                    result.Add(nextDepartment.WebHook.WebhookPath);
                }
            }
            else
            {
                var nextAttendant = lstAttendants.SkipWhile(x => x.AttendantId != lastDisQualifiedLeadInsertAttendant.AttendantID).Skip(1).FirstOrDefault();

                if (nextAttendant == null)
                {
                    nextAttendant = lstAttendants[0];
                }

                result.Add(nextDepartment.DepartmentId.ToString());
                result.Add(nextAttendant.AttendantId.ToString());
                if (nextDepartment.WebHook != null)
                {
                    result.Add(nextDepartment.WebHook.WebhookPath);
                }
            }

            return(result);
        }