public void UpdateLeadStatus(AVOAIALifeEntities Context, int leadNo, int status) { try { LeadStatus leadStatus = new LeadStatus(); leadStatus.samsLeadNumber = leadNo; leadStatus.status = status; leadStatus.statusDateTime = DateTime.Now.ToString("yyyy-MM-dd h:mm tt"); #region Log Input tbllogxml objlogxml = new tbllogxml(); objlogxml.Description = "Lead status request"; objlogxml.PolicyID = leadNo.ToString(); objlogxml.XMlData = Newtonsoft.Json.JsonConvert.SerializeObject(leadStatus); objlogxml.CreatedDate = DateTime.Now; Context.tbllogxmls.Add(objlogxml); #endregion LeadResponse leadResponse = new LeadResponse(); InvokeApi <LeadStatus, LeadResponse>(leadStatus, "sams/update/status", ref leadResponse); #region Log output tbllogxml outlogxml = new tbllogxml(); outlogxml.Description = "Lead Update Response"; outlogxml.PolicyID = leadNo.ToString(); outlogxml.XMlData = Newtonsoft.Json.JsonConvert.SerializeObject(leadResponse); outlogxml.CreatedDate = DateTime.Now; Context.tbllogxmls.Add(outlogxml); #endregion } catch (Exception ex) { } }
public void UpdateLead(AVOAIALifeEntities Context, Prospect prospect) { try { LeadCreation leadCreation = new LeadCreation(); if (!string.IsNullOrEmpty(prospect.AssignedTo)) { leadCreation.AgentCode = prospect.AssignedTo; } else { leadCreation.AgentCode = Context.tblMasIMOUsers.Where(a => a.UserID == prospect.UserName).Select(a => a.AgentCode).FirstOrDefault(); } leadCreation.AvoLeadNumber = prospect.ContactID.ToString(); int Type = Context.tblMasCommonTypes.Where(a => a.Description == prospect.Type).Select(a => a.CommonTypesID).FirstOrDefault(); if (Type == 0) { Type = Convert.ToInt32(prospect.Type); } leadCreation.AvoLeadType = Context.tblMasCommonTypes.Where(a => a.CommonTypesID == Type && (a.MasterType == "Type" || a.MasterType == "BancaType")).Select(a => a.Code).FirstOrDefault(); string role = Context.usp_GetCurrentUserRole(leadCreation.AgentCode).FirstOrDefault(); if (role == "FPC-Banca") { leadCreation.Channel = "BA"; } else { leadCreation.Channel = "AG"; } if (string.IsNullOrEmpty(prospect.SamsLeadNumber)) { leadCreation.Flag = "NEW"; } else { leadCreation.Flag = "UPDATE"; } //int titleId = Convert.ToInt32(prospect.Title); leadCreation.LeadTitle = Context.tblMasCommonTypes.Where(a => a.Description == prospect.Salutation && a.MasterType == "Salutation").Select(a => a.Code).FirstOrDefault(); if (string.IsNullOrEmpty(leadCreation.LeadTitle)) { leadCreation.LeadTitle = prospect.Salutation; } leadCreation.LeadFirstName = prospect.Name; leadCreation.LeadLastName = prospect.LastName; leadCreation.LeadContactNumber = prospect.Mobile; leadCreation.NIC = prospect.NIC; leadCreation.LeadEmail = prospect.Email; leadCreation.UserId = Context.tblMasIMOUsers.Where(a => a.UserID == prospect.UserName).Select(a => a.AgentCode).FirstOrDefault();; leadCreation.LeadPlace = prospect.Place; leadCreation.LeadContactOffice = prospect.Work; leadCreation.LeadContactResident = prospect.Home; leadCreation.Address1 = prospect.objAddress.Address1; leadCreation.Address2 = prospect.objAddress.Address2; leadCreation.Address3 = prospect.objAddress.Address3; leadCreation.MaritalStatus = prospect.MaritalStatus; leadCreation.Gender = prospect.Gender; leadCreation.DOB = Convert.ToDateTime(prospect.DateofBirth).ToString("yyyy-MM-dd"); leadCreation.SamsLeadNumber = Convert.ToInt32(prospect.SamsLeadNumber); leadCreation.LeadIntroducer = string.IsNullOrEmpty(prospect.IntroducerCode) == false?prospect.IntroducerCode.TrimEnd() : ""; //leadCreation.AssignedTo = prospect.AssignedTo; //AuthenticateSams(); #region Log Input tbllogxml objlogxml = new tbllogxml(); objlogxml.Description = "Sams Lead Update request"; objlogxml.PolicyID = leadCreation.AvoLeadNumber; objlogxml.UserID = prospect.CreatedBy; objlogxml.XMlData = Newtonsoft.Json.JsonConvert.SerializeObject(leadCreation); objlogxml.CreatedDate = DateTime.Now; Context.tbllogxmls.Add(objlogxml); Context.SaveChanges(); #endregion LeadResponse leadResponse = new LeadResponse(); InvokeApi <LeadCreation, LeadResponse>(leadCreation, "sams/", ref leadResponse); #region Log output tbllogxml outlogxml = new tbllogxml(); outlogxml.Description = "Sams Lead Update response"; outlogxml.PolicyID = leadCreation.AvoLeadNumber; outlogxml.UserID = prospect.CreatedBy; outlogxml.XMlData = Newtonsoft.Json.JsonConvert.SerializeObject(leadResponse); outlogxml.CreatedDate = DateTime.Now; Context.tbllogxmls.Add(outlogxml); Context.SaveChanges(); #endregion if (leadResponse.body != null) { if (!string.IsNullOrEmpty(leadResponse.body.SamsLeadNumber) && leadResponse.body.SamsLeadNumber != "0") { prospect.SamsLeadNumber = leadResponse.body.SamsLeadNumber; } } } catch (Exception ex) { if (string.IsNullOrEmpty(prospect.SamsLeadNumber)) { prospect.SamsLeadNumber = ""; } } }