Ejemplo n.º 1
0
        private bool RetrieveNewestContact()
        {
            bool result = false;

            try
            {
                if (!string.IsNullOrEmpty(SessionManager.GetProgramParameterByKey("LeadRecordId", HttpContext.Session)))
                {
                    result = true;
                    string leadId = SessionManager.GetProgramParameterByKey("LeadRecordId", HttpContext.Session);
                    ScreenViewer.API.ExternalData.ContactRecordController contactController = new API.ExternalData.ContactRecordController();

                    if (leadId != "" && leadId != null)
                    {
                        var actionResult = contactController.GetContactRecordByLeadId(leadId);
                        var response     = actionResult as OkNegotiatedContentResult <ContactRecord>;

                        if (response != null)
                        {
                            ContactRecord contactRecord = response.Content;

                            if (contactRecord.ContactRecordDetails.Count > 0)
                            {
                                List <QuestVal> questvals = new List <QuestVal>();

                                foreach (var item in contactRecord.ContactRecordDetails)
                                {
                                    QuestVal QV = new QuestVal();
                                    QV.QuestionID      = item.QuestionId.ToString();
                                    QV.Response        = item.QuestionResponseValue;
                                    QV.DisplayResponse = item.QuestionResponseText;
                                    questvals.Add(QV);
                                }

                                SessionManager.AddUpdateQuestions(questvals, HttpContext.Session);
                            }
                        }
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void CreateContactRecord(string projectName)
        {
            System.Web.Http.IHttpActionResult result = null;
            List <ContactAttribute>           lstContactAttribute = null;
            ContactAttribute            contactAttribute          = null;
            ContactRecord               contactRecord             = null;
            Dictionary <string, string> scriptsParameter;
            DateTime timeUtc           = DateTime.UtcNow;
            string   previous          = string.Empty;
            bool     isLeadClientFound = false;

            try
            {
                contactRecord       = new ContactRecord();
                lstContactAttribute = new List <ContactAttribute>();
                scriptsParameter    = SessionManager.GetScriptParameter(HttpContext.Session);

                if (!string.IsNullOrEmpty(SessionManager.GetProgramParameterByKey("CallID", HttpContext.Session)))
                {
                    contactRecord.ClientCallId = SessionManager.GetProgramParameterByKey("CallID", HttpContext.Session);
                }
                else
                {
                    contactRecord.ClientCallId = "N/P";
                }

                if (!string.IsNullOrEmpty(SessionManager.GetProgramParameterByKey("ANI", HttpContext.Session)))
                {
                    contactRecord.ANI = SessionManager.GetProgramParameterByKey("ANI", HttpContext.Session);
                }
                else
                {
                    contactRecord.ANI = "N/P";
                }

                if (!string.IsNullOrEmpty(SessionManager.GetProgramParameterByKey("Previous", HttpContext.Session)))
                {
                    previous = SessionManager.GetProgramParameterByKey("Previous", HttpContext.Session);
                }

                if (string.IsNullOrEmpty(SessionManager.GetUserId(HttpContext.Session)) && string.IsNullOrEmpty(SessionManager.GetClientId(HttpContext.Session)))
                {
                    throw new Exception("User OR Client not found while creating contact record.");
                }

                try
                {
                    TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["timeZone"]);
                    DateTime     dateTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, timeZone);
                    contactRecord.CallStartDateTime = dateTime;
                    contactRecord.ModifiedDate      = dateTime;
                    contactRecord.ProjectName       = projectName;
                    contactRecord.CallState         = "INPRC";
                    contactRecord.UserId            = SessionManager.GetUserId(HttpContext.Session);
                    contactRecord.ClientId          = SessionManager.GetClientId(HttpContext.Session);

                    if (!string.IsNullOrEmpty(SessionManager.ReturnParameter(HttpContext.Session, "LeadID")))
                    {
                        contactRecord.LeadRecordId = SessionManager.ReturnParameter(HttpContext.Session, "LeadID");
                    }

                    if (!string.IsNullOrEmpty(SessionManager.GetScriptURL(Session)))
                    {
                        contactRecord.URL = SessionManager.GetScriptURL(Session);
                    }

                    foreach (var item in scriptsParameter)
                    {
                        contactAttribute = new ContactAttribute();
                        contactAttribute.ContactAttributeName  = item.Key;
                        contactAttribute.ContactAttributeValue = item.Value;
                        contactAttribute.CreatedDate           = contactRecord.CallStartDateTime.Value;
                        contactAttribute.ClientId = SessionManager.GetClientId(HttpContext.Session);
                        lstContactAttribute.Add(contactAttribute);
                    }

                    contactRecord.ContactAttributes = lstContactAttribute;
                }
                catch { }

                ScreenViewer.API.ExternalData.ContactRecordController CRC = new API.ExternalData.ContactRecordController();

                // Check LeadRecord and ClientCallId Exist then retrive client call id
                if (!string.IsNullOrEmpty(contactRecord.LeadRecordId) && !string.IsNullOrEmpty(contactRecord.ClientCallId))
                {
                    result = CRC.GetContactRecordByLeadClient(contactRecord.LeadRecordId, contactRecord.ClientCallId);

                    if (result != null && result != result as System.Web.Http.Results.NotFoundResult)
                    {
                        isLeadClientFound = true;
                        var response = result as OkNegotiatedContentResult <ContactRecord>;
                        contactRecord = response.Content;
                        SessionControl.SessionManager.StoreContactId(HttpContext.Session, contactRecord.ContactId);
                        SessionManager.StoreProgramParameter("ClientCallId", contactRecord.ClientCallId, Session);
                    }
                }

                if (!isLeadClientFound)
                {
                    if (string.IsNullOrEmpty(previous))
                    {
                        result = CRC.PostContactRecord(contactRecord);
                    }
                    else
                    {
                        result = CRC.GetContactRecordByContactId(Convert.ToInt32(previous));
                    }

                    if (result != null && result != result as System.Web.Http.Results.NotFoundResult)
                    {
                        var response = result as OkNegotiatedContentResult <ContactRecord>;
                        contactRecord = response.Content;
                        SessionControl.SessionManager.StoreContactId(HttpContext.Session, contactRecord.ContactId);
                        SessionManager.StoreProgramParameter("ClientCallId", contactRecord.ClientCallId, Session);
                    }
                    else
                    {
                        throw new Exception("Unable to create contact record.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }