Exemple #1
0
        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);
        }
Exemple #2
0
        public void CreateDisQualifiedLead(DisqualifiedLead disqualifiedLead, string webHookPath, string email, string status, bool reprocess)
        {
            DisQualifiedLeadServices disQualifiedLeadService = new DisQualifiedLeadServices();

            try
            {
                //string accessToken = GetNewAccessToken();
                //string portal_name = "https://luxassessoria.bitrix24.com.br/rest/6432/izu90pf0b1l3gjpr/";

                string url                = string.Format("{0}crm.lead.add.json", webHookPath);
                string queue              = status;
                string sourceID           = "";
                string DateJobEnd         = "";
                string DateBorn           = "";
                string PrevSituationStart = "";
                string SituationStart     = "";
                int    PrevSituation      = 0;
                int    Situation          = 0;
                int    SegJobReceive      = 0;

                //if (status == "DPP")
                //    queue = "IN_PROCESS";
                //else if (status == "135")
                //    queue = "1";
                //else if (status == "PLUSS")
                //    queue = "PROCESSED";
                //else
                //    queue = "NEW";

                if (webHookPath.Contains("startprev"))
                {
                    SituationStart = Utility.Util.GetYouAreItemFormStart(disqualifiedLead.Situation);
                    queue          = "NEW";
                    sourceID       = "4";

                    if (disqualifiedLead.PrevSituation != null && disqualifiedLead.PrevSituation != "")
                    {
                        PrevSituationStart = Utility.Util.GetPrevSituationItemFormStart(disqualifiedLead.PrevSituation);
                    }
                    if (disqualifiedLead.SegJobReceive != null && disqualifiedLead.SegJobReceive != "")
                    {
                        SegJobReceive = Utility.Util.GetReceivedWorkInsurancesItemFormStart(disqualifiedLead.SegJobReceive);
                    }
                    if (disqualifiedLead.DateJobEnd != null && disqualifiedLead.DateJobEnd != "")
                    {
                        DateJobEnd = disqualifiedLead.DateJobEnd;
                    }
                    if (disqualifiedLead.DateBorn != null && disqualifiedLead.DateBorn != "")
                    {
                        DateBorn = disqualifiedLead.DateBorn;
                    }


                    var data = new
                    {
                        fields = new
                        {
                            TITLE                = disqualifiedLead.FirstName,
                            NAME                 = disqualifiedLead.FirstName,
                            STATUS_ID            = queue,
                            OPENED               = "Y",
                            ASSIGNED_BY_ID       = disqualifiedLead.AttendantID,
                            COMPANY_TITLE        = disqualifiedLead.FirstName,
                            SOURCE_ID            = sourceID,
                            COMMENTS             = "(Q)",
                            UF_CRM_1606226135410 = SituationStart,
                            UF_CRM_1606226151075 = PrevSituationStart,
                            UF_CRM_1601980780168 = SegJobReceive,
                            UF_CRM_1601984930150 = DateJobEnd,
                            UF_CRM_1601980069351 = DateBorn,

                            //COMPANY_TITLE = contactName,
                            //UF_CRM_1605728591038 = new List<UF_CRM_1605728591038>() { new UF_CRM_1605728591038() { ID = "44", VALUE = "TRABALHEI REGISTRADA antes do nascer." } }.ToArray(),
                            PHONE = new List <Phone>()
                            {
                                new Phone()
                                {
                                    VALUE_TYPE = "WORK", TYPE_ID = "PHONE", VALUE = disqualifiedLead.Phone
                                }
                            }.ToArray()
                            //EMAIL = new List<Email>() { new Email() { VALUE_TYPE = "WORK", TYPE_ID = "EMAIL", VALUE = email } }.ToArray()
                        },
                        @params = new
                        {
                            REGISTER_SONET_EVENT = "Y"
                        }
                    };

                    PostToAPI(url, "", data);
                    if (!reprocess)
                    {
                        disQualifiedLeadService.InsertDisQualifiedLead(disqualifiedLead);
                    }
                }
                else
                {
                    Situation = Utility.Util.GetYouAreItemForm(disqualifiedLead.Situation);
                    queue     = "8";
                    sourceID  = "58";

                    if (disqualifiedLead.PrevSituation != null && disqualifiedLead.PrevSituation != "")
                    {
                        PrevSituation = Utility.Util.GetPrevSituationItemForm(disqualifiedLead.PrevSituation);
                    }
                    if (disqualifiedLead.SegJobReceive != null && disqualifiedLead.SegJobReceive != "")
                    {
                        SegJobReceive = Utility.Util.GetReceivedWorkInsurancesItemForm(disqualifiedLead.SegJobReceive);
                    }
                    if (disqualifiedLead.DateJobEnd != null && disqualifiedLead.DateJobEnd != "")
                    {
                        DateJobEnd = disqualifiedLead.DateJobEnd;
                    }
                    if (disqualifiedLead.DateBorn != null && disqualifiedLead.DateBorn != "")
                    {
                        DateBorn = disqualifiedLead.DateBorn;
                    }

                    var data = new
                    {
                        fields = new
                        {
                            TITLE                = disqualifiedLead.FirstName,
                            NAME                 = disqualifiedLead.FirstName,
                            STATUS_ID            = queue,
                            OPENED               = "Y",
                            OPPORTUNITY          = 12,
                            ASSIGNED_BY_ID       = disqualifiedLead.AttendantID,
                            COMPANY_TITLE        = disqualifiedLead.FirstName,
                            SOURCE_ID            = sourceID,
                            UF_CRM_1597496714    = Situation,
                            UF_CRM_1597497342    = PrevSituation,
                            UF_CRM_1597497546    = SegJobReceive,
                            UF_CRM_1597497700    = disqualifiedLead.DateJobEnd != null ? disqualifiedLead.DateJobEnd : "",
                            UF_CRM_1580316545358 = disqualifiedLead.DateBorn != null ? disqualifiedLead.DateBorn : "",
                            COMMENTS             = "(NQ)",
                            //UF_CRM_1577711078940 = 4293,
                            //UF_CRM_1605798367693 = "TESTE2",
                            //UF_CRM_1605803452106 = "64",
                            //UF_CRM_1605728591038 = "44",
                            //UF_CRM_1605803452106 = new List<UF_CRM_1605728591038>() { new UF_CRM_1605728591038() { ID = "62",  VALUE = "Sim" } }.ToArray(),
                            PHONE = new List <Phone>()
                            {
                                new Phone()
                                {
                                    VALUE_TYPE = "WORK", TYPE_ID = "PHONE", VALUE = disqualifiedLead.Phone
                                }
                            }.ToArray()
                            //EMAIL = new List<Email>() { new Email() { VALUE_TYPE = "WORK", TYPE_ID = "EMAIL", VALUE = email } }.ToArray()
                        },
                        @params = new
                        {
                            REGISTER_SONET_EVENT = "Y"
                        }
                    };
                    PostToAPI(url, "", data);
                    if (!reprocess)
                    {
                        disQualifiedLeadService.InsertDisQualifiedLead(disqualifiedLead);
                    }
                }


                //BitrixLead lead = new BitrixLead();

                //lead.TITLE = title;
                //lead.CURRENCY_ID = "RUB";
                //lead.STATUS_ID = "NEW";
                //lead.OPENED = "Y";
                //lead.OPPORTUNITY = opportunity.ToString();

                //if (!string.IsNullOrEmpty(contactName))
                //    lead.COMPANY_TITLE = contactName;

                //if (!string.IsNullOrEmpty(PhoneNumber))
                //    lead.PHONE = new List<Phone>() { new Phone() { VALUE_TYPE = "WORK", TYPE_ID = "PHONE", VALUE = PhoneNumber } }.ToArray();

                //if (!string.IsNullOrEmpty(email))
                //    lead.EMAIL = new List<Email>() { new Email() { VALUE_TYPE = "WORK", TYPE_ID = "EMAIL", VALUE = email } }.ToArray();
            }
            catch (Exception exc)
            {
            }
        }