public ActionResult Create(Web.ViewModel.AccountInformationViewModel vm)
        {
            Report newRecord  = new Report();
            var    newAccount = vm.account;

            vm.account.ParentLead       = vm.leadId;
            vm.account.AssignedSalesRep = vm.assignedsa.UserId;
            vm.account.AACreator        = vm.assignedaa.UserId;
            var appointmentforlead = _AppointmentRepository.GetAppointmentByLeadId(vm.leadId);

            foreach (var appointment in appointmentforlead)
            {
                if (appointment.Score == "Good")
                {
                    newRecord = _ReportRepository.CheckExistingRecord(appointment.AssignedSalesAgent);
                    newRecord.MonthlyAccounts++;
                    var accountsforlead = _AccountRepository.GetAccountsByLeadId(vm.leadId);
                    if (accountsforlead.Count() == 0)
                    {
                        newRecord.MonthlyCloses++;
                    }
                    _ReportRepository.SaveReports(newRecord);

                    break;
                }
            }
            _AccountRepository.SaveAccounts(newAccount);

            //TO assign status to the lead for which account was created.

            Lead lead = new Lead();

            lead        = _LeadRepository.LeadByLeadID(vm.leadId);
            lead.Status = "Customer";
            _LeadRepository.SaveLead(lead);



            //return RedirectToActionPermanent("Index");
            return(Json(new { redirectToUrl = Url.Action("Index") }));
        }
Beispiel #2
0
        public ActionResult CallProfile(int LeadId)
        {
            ProfileViewModel pvm       = new ProfileViewModel();
            Report           newRecord = new Report();

            _logger.Debug("Trying to make a call.");
            var username = HttpContext.User.Identity.Name;

            pvm.user = _UserRepository.GetUserByUsername(username);

            newRecord = _ReportRepository.CheckExistingRecord(pvm.user.UserId);
            newRecord.MonthlyAppointments = newRecord.MonthlyAppointments + 1;
            newRecord.AssignedAAUserID    = pvm.user.UserId;
            _ReportRepository.SaveReports(newRecord);

            // Please remember to include this part of the code whenever Click to Dial is implemented.
            Lead lead = new Lead();

            lead         = _service.GetLeadByLeadId(LeadId);
            pvm.lead     = lead;
            pvm.accounts = GetNumberOfAccounts(lead.LeadId);

            // Call to Extend API for calling the customer

            var phoneuser = _PhoneUserRepos.GetPhoneUser(pvm.user.UserId);
            //string user = phoneuser.UserName;
            //string password = phoneuser.Password;
            var num = lead.PrimaryPhoneNumber;

            if (num.Contains("("))
            {
                num = num.Remove(0, 1);
                num = num.Remove(3, 1);
                num = num.Remove(7, 1);
                num = num.Remove(3, 1);
            }
            string user     = "******";
            string password = "******";
            //string snum = num;
            //num = "1" + num;
            long phoneNumberDialing = Convert.ToInt64(num);

            //if (lead.PrimaryPhoneChecked == true)
            //{
            //    phoneNumberDialing = int.Parse(lead.PrimaryPhoneNumber);
            //}
            //else
            //{
            //    phoneNumberDialing = int.Parse(lead.AddtionalPhoneNumber);
            //}
            string xml = "<request method= \"switchvox.users.call\"> <parameters> <account_id>" + /*phoneuser.AccountId*/ 1155 + "</account_id><dial_first>" + phoneuser.Extension + "</dial_first> <dial_second>" + phoneNumberDialing + "</dial_second> <variables> <variable>balance=300</variable> </variables> </parameters> </request> ";
            //string xml = "<request method= \"switchvox.users.call\"> <parameters> <account_id>1106</account_id><dial_first>326</dial_first> <dial_second>326</dial_second> <variables> <variable>balance=300</variable> </variables> </parameters> </request> ";
            //string xml = "<request method=\"switchvox.extensions.getInfo\"> <parameters> <extensions> <extension>327</extension> <extension>326</extension> </extensions> </parameters></request> ";
            string url = ConfigReader.VoipIP;

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            //string s = "id="+Server.UrlEncode(xml);
            byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
            req.Method        = "POST";
            req.ContentType   = "text/xml;charset=utf-8";
            req.ContentLength = requestBytes.Length;
            req.Credentials   = new NetworkCredential(user, password);
            ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return(true); };

            Stream requestStream = req.GetRequestStream();

            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();

            HttpWebResponse res     = (HttpWebResponse)req.GetResponse();
            StreamReader    sr      = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
            string          backstr = sr.ReadToEnd();

            sr.Close();
            res.Close();


            //Make sure that Customer is not converted to Warm Lead here
            if (lead.Status != "Customer")
            {
                lead.Status = "Warm Lead";
            }
            _leadRepos.SaveLead(lead);
            return(View(pvm));
        }