Example #1
0
        public void ConvertTo_returns_correct_result_for_DateTime()
        {
            DateTime?val = NullSafe.ConvertTo <DateTime>("2012-10-19");

            Assert.IsTrue(val.HasValue);
            Assert.AreEqual(new DateTime(2012, 10, 19), val.Value);
        }
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                JToken token = JToken.Load(reader);

                switch (token.Type)
                {
                case JTokenType.Integer:
                    return(token.ToObject <int>());

                case JTokenType.Float:
                    return(token.ToObject <int>());

                case JTokenType.String:
                    return(int.Parse(token.ToString()));

                case JTokenType.Boolean:
                    return(NullSafe.NullSafeInteger(token, 0));

                case JTokenType.Null:
                    return(objectType == typeof(int?));

                default:
                    throw new JsonSerializationException("Unexpected token type: " + token.Type);
                }
            }
Example #3
0
        public void ConvertTo_returns_correct_result_for_ulong()
        {
            ulong?val = NullSafe.ConvertTo <ulong>("5");

            Assert.IsTrue(val.HasValue);
            Assert.AreEqual(5, val.Value);
        }
Example #4
0
        public CommonParams(HttpRequestMessage request)
        {
            if (request?.GetQueryNameValuePairs() == null)
            {
                return;
            }
            var value = request.GetQueryNameValuePairs().FirstOrDefault(x => x.Key == "TimeOutInMill").Value;

            if (value != null)
            {
                TimeoutInMill = NullSafe.NullSafeInteger(value, TimeoutInMill);
            }

            //THIS IS ALSO USED BY ZILLOW 'single user request'
            value = request.GetQueryNameValuePairs().FirstOrDefault(x => x.Key == "UseOnlyThisUserId").Value;
            if (value != null)
            {
                UseOnlyThisUserId = NullSafe.NullSafeInteger(value, UseOnlyThisUserId);
            }

            value = request.GetQueryNameValuePairs().FirstOrDefault(x => x.Key == "DebugModeType").Value;
            if (value != null)
            {
                EnumLib.TryParse(value, out DebugModeType);
            }
        }
        protected void Application_Start()
        {
            new DataConnections();

            var formatters    = GlobalConfiguration.Configuration.Formatters;
            var jsonFormatter = formatters.JsonFormatter;

            jsonFormatter.SerializerSettings = JsonSettings;

            LeadWebServices = new ApiWebServices(DataContextType.Database, DataConnections.DataContextLoanTekRead).Get(new Filter
            {
                PropertySearchItems = new List <SearchAndCompare.ColumnSearchItem>
                {
                    new SearchAndCompare.ColumnSearchItem
                    {
                        Column      = "CategoryType",
                        CompareType = Types.SearchAndCompare.CompareType.EqualTo,
                        SearchTerm  = Types.Api.ApiCategoryTypes.CRM.ToString()
                    }
                }
            });


            GlobalConfiguration.Configure(WebApiConfig.Register);
            GlobalConfiguration.Configuration.Filters.Add(new CustomExceptionFilterAttribute());

            ApiObject = new LeadsClientsApi()
            {
                Versions = new List <Version>()
                {
                    new Version()
                    {
                        MajorVersionId = 1,
                        MinorVersionId = 1,
                        VersionStatus  = Types.Api.VersionStatusType.Beta,
                        Created        = Convert.ToDateTime("04/01/2016"),
                        LastUpdated    = Convert.ToDateTime("07/08/2016")
                    }
                }
            };

            var clientId = 399;

            Debug.WriteLine("ClientId:" + clientId + " LeadsController Auth key:" + AuthToken.EncryptAuthKey(clientId, NewLeadsController.ApiObject.ApiName));
            Debug.WriteLine("ClientId:" + clientId + " WidgetController Auth key:" + AuthToken.EncryptAuthKey(clientId, WidgetController.WebServiceName));

            string key = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(x => x.ToLower().Equals("useonlythisuserid"));

            Global.UseOnlyThisUserId = NullSafe.NullSafeInteger(ConfigurationManager.AppSettings[key], 0);

            key = ConfigurationManager.AppSettings.AllKeys.FirstOrDefault(x => x.ToLower().Equals("Types.Api.ServerStatusType"));
            Global.ServerStatusType = EnumLib.TryParse <Types.Api.ApiStatusType>((key != null) ? ConfigurationManager.AppSettings[key] : ((Debugger.IsAttached) ? Types.Api.ApiStatusType.Testing : Types.Api.ApiStatusType.Live).ToString());

            if (!Debugger.IsAttached)
            {
                this.initCommonData();
            }
        }
Example #6
0
        public static bool IsCastleDynamicProxy(object obj)
        {
            Type type = obj.GetType();

// ReSharper disable PossibleNullReferenceException
            return(NullSafe.Execute(() => type.FullName.StartsWith("Castle.Proxies.")) ||
                   ProxyNamingCriteria.IsMatch(type.Name));
// ReSharper restore PossibleNullReferenceException
        }
        public void Dirty_Not_Equals_Self_Should_Be_False()
        {
            var dirty = new NullSafe <TestObject>(new TestObject()
            {
                Name = "some"
            });

            (dirty != dirty).Should().Be(false);
        }
        public void Dirty_Not_Equals_Null_Should_Be_True()
        {
            var dirty = new NullSafe <TestObject>(new TestObject()
            {
                Name = "some"
            });

            (dirty != null).Should().Be(true);
        }
        public void Dirty_Equals_Self_Should_Be_True()
        {
            var dirty = new NullSafe <TestObject>(new TestObject()
            {
                Name = "some"
            });

            (dirty == dirty).Should().Be(true);
        }
Example #10
0
        public void ConvertTo_returns_null_for_impossible_conversion()
        {
            int?val = NullSafe.ConvertTo <int>("foo");

            Assert.IsFalse(val.HasValue);

            val = NullSafe.ConvertTo <int>(null);

            Assert.IsFalse(val.HasValue);
        }
        public void Pristine_Equals_Null_Should_Be_True()
        {
            var pristine = new NullSafe <TestObject>();

            using (new AssertionScope())
            {
                (pristine == null).Should().Be(true);
                TestObject to = pristine;
                to.Name.Should().BeNull();
            }
        }
Example #12
0
        private void setPort(string s)
        {
            int ss = NullSafe.NullSafeInteger(s.Split(' ').LastOrDefault());

            if (ss < 1)
            {
                Console.WriteLine("Invalid portvalue:" + ss);
            }
            Global.Config.Port = ss;
            Global.Config.SaveConfig();
            setResponse("Port set to:" + ss);
        }
        public void Dirty_Equals_Null_Should_Be_False()
        {
            var dirty = new NullSafe <TestObject>(new TestObject {
                Name = "some"
            });

            using (new AssertionScope())
            {
                (dirty == null).Should().Be(false);
                TestObject to = dirty;
                to.Name.Should().Be("some");
            }
        }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            //use with the attribute [SkipMyGlobalActionFilter]
            if (actionContext.ActionDescriptor.GetCustomAttributes <SkipMyGlobalActionFilterAttribute>(false).Any())
            {
                return;
            }

            //new Task(() => { ).Start(); //this will execute in its own thread allowing the request to continue processing independently of the 'Save'
            //var durationInMilli = (DateTime.Now - startTime).Milliseconds;
            //Debug.WriteLine("PreProcessQuoteRequestFilter hit...pre-process time: " + durationInMilli);

            var newRequest = new AApiRequest();

            actionContext.Request.Properties[Global.ARequestPropertyName] = newRequest;
            Task.Run(() =>
            {
                newRequest.LocalServerName = Global.LocalServerName;
                newRequest.ApiName         = Global.ApiObject.ApiName;
                newRequest.ApiEndPoint     = actionContext.Request.RequestUri.AbsolutePath.ToLower();
                newRequest.Url             = actionContext.Request.RequestUri.AbsoluteUri;
                newRequest.RemoteIP        = ClientInfo.GetIPAddress(actionContext.Request);
                try
                {
                    foreach (var key in actionContext.ActionArguments.Keys)
                    {
                        switch (key.ToLower())
                        {
                        case "authtoken": newRequest.AuthToken = actionContext.ActionArguments[key].ToString(); break;

                        case "clientid": newRequest.ClientId = NullSafe.NullSafeInteger(actionContext.ActionArguments[key]); break;

                        //case "request": (actionContext.ActionArguments[key] is string) ? newRequest.RawRequest = actionContext.ActionArguments[key].ToString() : ; break;
                        //case "loanpricerloanrequest": newRequest.RawRequest = JsonConvert.SerializeObject(actionContext.ActionArguments[key]); break;
                        case "commonparams": break;

                        default:
                            newRequest.RawRequest = (actionContext.ActionArguments[key] is string) ? newRequest.RawRequest = actionContext.ActionArguments[key].ToString() : JsonConvert.SerializeObject(actionContext.ActionArguments.FirstOrDefault()); break;
                        }
                    }
                }
                catch (Exception ex) { newRequest.RawRequest = "ERROR trying to read Content:" + ex.Message; }
                if (string.IsNullOrEmpty(newRequest.RawRequest))
                {
                    newRequest.RawRequest = actionContext.Request.RequestUri.Query;
                }
                newRequest.Save();
            });

            base.OnActionExecuting(actionContext);
        }
Example #15
0
        public HttpResponseMessage Get()  //string encryptedClientId
        {
            GetParams(Request);
            var hubVerifyToken = GetParam("hub.verify_token");

            Email.SendEmail("*****@*****.**", "GET on FB API", "VT=" + NullSafe.NullSafeString(hubVerifyToken) + ", HC=" + NullSafe.NullSafeString(GetParam("hub.challenge")), true, string.Empty, string.Empty);

            if (!SecurityToken.Equals(hubVerifyToken))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid Verify Token"));
            }

            var hubChallenge = GetParam("hub.challenge");
            var response     = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(hubChallenge, Encoding.UTF8, "application/json");
            return(response);
        }
Example #16
0
        public HttpResponseMessage AddBankrateXmlLead(HttpRequestMessage request)
        {
            this.ResponseFormatter = new XmlMediaTypeFormatter();

            const string endpoint         = "AddNewLead/Bankrate/XML";
            const int    bankrateClientId = 903;
            const int    bankrateUserId   = 2383;

            var encryptedClientId = this.Request.RequestUri.ParseQueryString()["c"];
            int clientId          = !string.IsNullOrEmpty(encryptedClientId) ? NullSafe.NullSafeInteger(Encryption.DecryptString(encryptedClientId)) : 0;

            if (clientId != bankrateClientId)
            {
                return(this.CreateErrorResponse(HttpStatusCode.Unauthorized, "Client is not valid for this web service.", endpoint));
            }

            bool checkForDuplicate = false;

            return(this.processXmlLead(request, encryptedClientId, bankrateUserId, endpoint, checkForDuplicate));
        }
Example #17
0
        public static Lead ConvertXmlSchema(MortgageLead dataLead)
        {
            if (dataLead == null)
            {
                return(null);
            }

            Lead lead = new Lead();

            LoanTekAPI.SetLeadDefaults(lead);
            lead.UserID = dataLead.UserId.ToInt();

            if (string.IsNullOrEmpty(dataLead.Status))
            {
                dataLead.Status = LeadStatus.Assigned.ToString();
            }

            LeadStatus leadStatus;

            if (Enum.TryParse(dataLead.Status, out leadStatus))
            {
                lead.StatusID = (int)leadStatus;
            }
            else
            {
                lead.StatusID = (int)LeadStatus.Unassigned;
            }

            #region Address update / cleanup

            var state = string.Empty;
            var zip   = string.Empty;
            if (dataLead.Borrower != null)
            {
                if (string.IsNullOrEmpty(dataLead.Borrower?.MailState))
                {
                    if (dataLead.Property != null)
                    {
                        state = dataLead.Property?.PropertyState;
                        zip   = dataLead.Property?.PropertyZip;
                    }
                }
                else
                {
                    state = dataLead.Borrower?.MailState;
                    zip   = dataLead.Borrower?.MailZip;
                }
            }
            if (string.IsNullOrEmpty(state) && !string.IsNullOrEmpty(zip))
            {
                using (LeadsDataContext dc = new LeadsDataContext())
                {
                    var result = dc.LeadsGetStateAbbreviationByZipCode(zip).FirstOrDefault();

                    if (result != null)
                    {
                        state = NullSafe.NullSafeString(result.stateabbv);
                    }
                }
            }
            if (!string.IsNullOrEmpty(state))
            {
                if (dataLead.Borrower != null)
                {
                    if (string.IsNullOrEmpty(dataLead.Borrower?.MailState))
                    {
                        dataLead.Borrower.MailState = state;
                    }
                }
                if (dataLead.Property != null)
                {
                    if (string.IsNullOrEmpty(dataLead.Property?.PropertyState))
                    {
                        dataLead.Property.PropertyState = state;
                    }
                }
            }

            #endregion

            #region Name update / cleanup

            if (dataLead.Borrower != null)
            {
                if (dataLead.Borrower?.FirstName != null)
                {
                    lead.FirstName = NullSafe.NullSafeString(dataLead.Borrower?.FirstName);
                }
                if (dataLead.Borrower?.LastName != null)
                {
                    lead.LastName = NullSafe.NullSafeString(dataLead.Borrower?.LastName);
                }
                if (string.IsNullOrEmpty(dataLead.Borrower?.LastName))
                {
                    var nameList = NullSafe.NullSafeString(dataLead.Borrower?.FirstName).Split(' ').ToList();
                    switch (nameList.Count)
                    {
                    case 1:
                        lead.FirstName = nameList[0];
                        break;

                    case 2:
                        lead.FirstName = nameList[0];
                        lead.LastName  = nameList[1];
                        break;

                    case 3:
                        lead.FirstName  = nameList[0];
                        lead.MiddleName = nameList[1];
                        lead.LastName   = nameList[2];
                        break;

                    case 4:
                        if (nameList.Count(w => w == "and") > 0)
                        {
                            lead.FirstName  = $"{nameList[0]} {nameList[1]} {nameList[2]}";
                            lead.MiddleName = string.Empty;
                            lead.LastName   = nameList[3];
                        }
                        else
                        {
                            lead.FirstName  = nameList[0];
                            lead.MiddleName = nameList[1];
                            lead.LastName   = $"{nameList[2]} {nameList[3]}";
                        }
                        break;
                    }
                }
            }

            #endregion

            if (dataLead.Borrower != null)
            {
                if (NullSafe.NullSafeString(dataLead?.Borrower?.GrossMonthlyIncome).Split('-').Length > 1)
                {
                    var income = NullSafe.NullSafeString(dataLead?.Borrower?.GrossMonthlyIncome).Split('-')[0];
                    dataLead.Borrower.GrossMonthlyIncome = income;
                }
                if (NullSafe.NullSafeString(dataLead?.Borrower?.FicoScore).Split('-').Length > 1)
                {
                    var fico = NullSafe.NullSafeString(dataLead?.Borrower?.FicoScore).Split('-')[0];
                    dataLead.Borrower.FicoScore = fico;
                }
            }

            lead.LenderId               = dataLead.LenderId;
            lead.PartnerId              = dataLead.PartnerId;
            lead.EmailScore             = NullSafe.NullSafeString(dataLead?.EmailScore);
            lead.HasMobilePhone         = NullSafe.NullSafeString(dataLead?.HasMobilePhone);
            lead.HasRecentPhoneActivity = NullSafe.NullSafeString(dataLead?.HasRecentPhoneActivity);
            lead.PhoneScore             = NullSafe.NullSafeString(dataLead?.PhoneScore);
            lead.ReferralType           = NullSafe.NullSafeString(dataLead?.ReferralType);
            lead.JornayaLeadId          = NullSafe.NullSafeString(dataLead?.JornayaLeadId);

            lead.CountyID = 0;
            lead.AdditionalInformation = NullSafe.NullSafeString(dataLead.AdditionalInformation).Replace("Unknown", "");
            lead.Age                    = NullSafe.NullSafeInteger(dataLead?.Borrower?.Age, 0);
            lead.AnnualIncome           = NullSafe.NullSafeInteger(dataLead?.Borrower?.GrossMonthlyIncome, 0) * 12;
            lead.Assigned               = DateTime.Now;
            lead.Created                = DateTime.Now;
            lead.CreditProfile          = NullSafe.NullSafeString(dataLead?.Borrower?.CreditRating).Replace("Unknown", "");
            lead.DateOfBirth            = NullSafe.NullSafeString(dataLead?.Borrower?.DateOfBirth).Replace("Unknown", "");
            lead.EmployerName           = NullSafe.NullSafeString(dataLead?.Borrower?.EmployerName).Replace("Unknown", "");
            lead.EmploymentLength       = NullSafe.NullSafeString(dataLead?.Borrower?.EmploymentLength).Replace("Unknown", "");
            lead.EmploymentLengthPeriod = NullSafe.NullSafeString(dataLead?.Borrower?.EmploymentLengthPeriod).Replace("Unknown", "");
            lead.EmploymentStatus       = NullSafe.NullSafeString(dataLead?.Borrower?.EmploymentStatus).Replace("Unknown", "");
            lead.FicoScore              = NullSafe.NullSafeInteger(dataLead?.Borrower?.FicoScore, 0);
            if (string.IsNullOrEmpty(lead.CreditProfile))
            {
                lead.CreditProfile = LoanTekAPI.GetCreditProfile((int)lead.FicoScore);
            }
            lead.FirstName          = StringUtilities.PropCase(StringUtilities.RemoveCharactersButKeepSpaces(lead.FirstName));
            lead.GrossMonthlyIncome = NullSafe.NullSafeInteger(dataLead?.Borrower?.GrossMonthlyIncome, 0);
            lead.HasCoBorrower      = dataLead.CoBorrower != null;
            lead.IPAddress          = NullSafe.NullSafeString(dataLead.IPAddress);
            if (lead.IPAddress.Length > 24)
            {
                lead.IPAddress = lead.IPAddress.Substring(0, 24);
            }
            lead.IsDeleted             = false;
            lead.IsVerified            = true;
            lead.LastName              = StringUtilities.PropCase(StringUtilities.RemoveCharactersButKeepSpaces(lead.LastName));
            lead.LiquidAssetsValue     = NullSafe.NullSafeInteger(dataLead?.Borrower?.LiquidAssetsValue, 0);
            lead.MailAddress           = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Borrower?.MailAddress).Replace("Unknown", ""));
            lead.MailAddress2          = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Borrower?.MailAddress2).Replace("Unknown", ""));
            lead.MailCity              = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Borrower?.MailCity).Replace("Unknown", ""));
            lead.MailState             = LocationServices.GetStateAbbreviation(NullSafe.NullSafeString(dataLead?.Borrower?.MailState).Replace("Unknown", "")).ToUpper();
            lead.MailZip               = NullSafe.NullSafeString(dataLead?.Borrower?.MailZip).Replace("Unknown", "");
            lead.MaritalStatus         = NullSafe.NullSafeString(dataLead?.Borrower?.MaritalStatus).Replace("Unknown", "");
            lead.MiddleName            = StringUtilities.PropCase(StringUtilities.RemoveCharacters(lead.MiddleName ?? string.Empty));
            lead.MonthlyDebt           = NullSafe.NullSafeInteger(dataLead?.Borrower?.MonthlyDebt, 0);
            lead.ResidenceLength       = NullSafe.NullSafeString(dataLead?.Borrower?.ResidenceLength).Replace("Unknown", "");
            lead.ResidenceLengthPeriod = NullSafe.NullSafeString(dataLead?.Borrower?.ResidenceLengthPeriod).Replace("Unknown", "");
            lead.SourceCreated         = NullSafe.NullSafeDate(dataLead.SourceCreated);
            lead.SourceFilterID        = LoanTekAPI.GetSourceFilterId(NullSafe.NullSafeInteger(dataLead.LeadSourceId, 0), NullSafe.NullSafeString(dataLead?.Loan?.LoanType).Replace("Unknown", ""));
            lead.SourceID              = NullSafe.NullSafeInteger(dataLead.LeadSourceId, 0);
            lead.SourceLeadID          = string.IsNullOrEmpty(dataLead.SourceLeadId) ? Guid.NewGuid().ToString() : NullSafe.NullSafeString(dataLead.SourceLeadId).Replace("Unknown", "");
            lead.SpouseFirstName       = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Borrower?.SpouseFirstName).Replace("Unknown", ""));
            lead.SpouseLastName        = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Borrower?.SpouseLastName).Replace("Unknown", ""));
            lead.SSN = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead?.Borrower?.SSN).Replace("Unknown", ""));
            if (dataLead.Property != null)
            {
                lead.StateID = NullSafe.NullSafeInteger(dataLead?.Property?.PropertyState, 0);
            }
            //lead.StatusID = (int)LeadStatus.Assigned;
            if (dataLead.Declarations != null)
            {
                lead.Bankruptcy           = NullSafe.NullSafeBoolean(dataLead.Declarations.Bankruptcy);
                lead.BankruptcyType       = NullSafe.NullSafeString(dataLead.Declarations.BankruptcyType).Replace("Unknown", "");
                lead.FirstTimeBuyer       = NullSafe.NullSafeBoolean(dataLead.Declarations.FirstTimeBuyer);
                lead.FHAEligible          = NullSafe.NullSafeBoolean(dataLead.Declarations.FHAEligible);
                lead.Foreclosed           = NullSafe.NullSafeBoolean(dataLead.Declarations.Foreclosed);
                lead.HomeOwner            = NullSafe.NullSafeBoolean(dataLead.Declarations.HomeOwner);
                lead.NeedPurchaseREAgent  = NullSafe.NullSafeBoolean(dataLead.Declarations.NeedPurchaseREAgent);
                lead.NeedSellingREAgent   = NullSafe.NullSafeBoolean(dataLead.Declarations.NeedSellingREAgent);
                lead.RealEstateAgentName  = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead.Declarations.RealEstateAgentName).Replace("Unknown", ""));
                lead.RealEstateAgentPhone = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead.Declarations.RealEstateAgentPhone).Replace("Unknown", ""));
                lead.VADisabled           = NullSafe.NullSafeBoolean(dataLead.Declarations.VADisabled);
                lead.VAEligible           = NullSafe.NullSafeBoolean(dataLead.Declarations.VAEligible);
                lead.VAFirstTime          = NullSafe.NullSafeBoolean(dataLead.Declarations.VAFirstTime);
                lead.VAType                   = NullSafe.NullSafeString(dataLead.Declarations.VAType).Replace("Unknown", "");
                lead.Veteran                  = NullSafe.NullSafeBoolean(dataLead.Declarations.Veteran);
                lead.WorkingWithRealtor       = NullSafe.NullSafeBoolean(dataLead.Declarations.WorkingWithRealtor);
                lead.EligibleForFHAStreamline = NullSafe.NullSafeBoolean(dataLead.Declarations.FHAStreamLineEligible);
                lead.EligibleForHARP          = NullSafe.NullSafeBoolean(dataLead.Declarations.HARPEligible);
            }
            if (dataLead.CoBorrower != null)
            {
                if (NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerFicoScore).Split('-').Length > 1)
                {
                    var fico = NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerFicoScore).Split('-')[0];
                    dataLead.CoBorrower.CoBorrowerFicoScore = fico;
                }
                lead.CoBorrowerAddress           = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerAddress).Replace("Unknown", ""));
                lead.CoBorrowerAge               = NullSafe.NullSafeInteger(dataLead?.CoBorrower?.CoBorrowerAge, 0);
                lead.CoBorrowerAnnualIncome      = NullSafe.NullSafeInteger(dataLead?.CoBorrower?.CoBorrowerAnnualIncome, 0);
                lead.CoBorrowerCity              = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerCity).Replace("Unknown", ""));
                lead.CoBorrowerCreditProfile     = NullSafe.NullSafeString(dataLead?.CoBorrower?.CreditRating).Replace("Unknown", "");
                lead.CoBorrowerDateOfBirth       = NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerDateOfBirth).Replace("Unknown", "");
                lead.CoBorrowerFicoScore         = NullSafe.NullSafeInteger(dataLead?.CoBorrower?.CoBorrowerFicoScore, 0);
                lead.CoBorrowerFirstName         = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerFirstName).Replace("Unknown", ""));
                lead.CoBorrowerLastName          = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerLastName).Replace("Unknown", ""));
                lead.CoBorrowerLiquidAssetsValue = NullSafe.NullSafeInteger(dataLead?.CoBorrower?.CoBorrowerLiquidAssetsValue, 0);
                lead.CoBorrowerMonthlyIncome     = NullSafe.NullSafeInteger(dataLead?.CoBorrower?.CoBorrowerMonthlyIncome, 0);
                lead.CoBorrowerSSN               = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerSSN).Replace("Unknown", ""));
                lead.CoBorrowerState             = NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerState).Replace("Unknown", "").ToUpper();
                lead.CoBorrowerVeteran           = NullSafe.NullSafeBoolean(dataLead?.CoBorrower?.CoBorrowerVeteran);
                lead.CoBorrowerZip               = NullSafe.NullSafeString(dataLead?.CoBorrower?.CoBorrowerZip).Replace("Unknown", "");
            }
            if (dataLead.ContactInfo != null)
            {
                lead.BestTimeToCall = NullSafe.NullSafeString(dataLead?.ContactInfo?.BestTimeToCall).Replace("Unknown", "");
                lead.Email          = NullSafe.NullSafeString(dataLead?.ContactInfo?.Email).ToLower();
                lead.Phone1         = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone1).Replace("Unknown", ""));
                lead.Phone1Type     = NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone1Type).Replace("Unknown", "");
                lead.Phone2         = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone2).Replace("Unknown", ""));
                lead.Phone2Type     = NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone2Type).Replace("Unknown", "");
                lead.Phone3         = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone3).Replace("Unknown", ""));
                lead.Phone3Type     = NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone3Type).Replace("Unknown", "");
                lead.Phone4         = StringUtilities.RemoveCharacters(NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone4).Replace("Unknown", ""));
                lead.Phone4Type     = NullSafe.NullSafeString(dataLead?.ContactInfo?.Phone4Type).Replace("Unknown", "");
            }
            if (dataLead.Loan != null)
            {
                lead.CashOut = NullSafe.NullSafeDecimal(StringUtilities.RemoveAllButNumericAndDecimal(dataLead?.Loan?.CashOut));
                if (lead.CashOut > 0)
                {
                    lead.WantsCashOut = true;
                }
                lead.DownPayment           = NullSafe.NullSafeInteger(dataLead?.Loan?.DownPayment, 0);
                lead.FirstMortgageBalance  = NullSafe.NullSafeInteger(dataLead?.Loan?.FirstMortgageBalance, 0);
                lead.FirstMortgagePayment  = NullSafe.NullSafeInteger(dataLead?.Loan?.FirstMortgagePayment, 0);
                lead.FirstMortgageRate     = NullSafe.NullSafeDecimal(dataLead?.Loan?.FirstMortgageRate);
                lead.FirstMortgageRateType = NullSafe.NullSafeString(dataLead?.Loan?.FirstMortgageRateType).Replace("Unknown", "");
                lead.FirstMortgageTerm     = NullSafe.NullSafeInteger(dataLead?.Loan?.FirstMortgageTerm, 0);
                lead.LoanAmount            = NullSafe.NullSafeInteger(dataLead?.Loan?.LoanAmount, 0);
                lead.LoanPurpose           = lead.CashOut > 0 ? "Cash Out" : NullSafe.NullSafeString(dataLead?.Loan?.LoanPurpose).Replace("Unknown", "");
                lead.LoanTimeFrame         = NullSafe.NullSafeString(dataLead?.Loan?.LoanTimeFrame).Replace("Item", "").Replace("Unknown", "");
                lead.LoanToValue           = NullSafe.NullSafeDecimal(dataLead?.Loan?.LoanToValue);
                lead.LoanType = NullSafe.NullSafeString(dataLead?.Loan?.LoanType).Replace("Unknown", "");
                lead.SecondMortgageBalance  = NullSafe.NullSafeInteger(dataLead?.Loan?.SecondMortgageBalance, 0);
                lead.SecondMortgagePayment  = NullSafe.NullSafeInteger(dataLead?.Loan?.SecondMortgagePayment, 0);
                lead.SecondMortgageRate     = NullSafe.NullSafeDecimal(dataLead?.Loan?.SecondMortgageRate);
                lead.SecondMortgageRateType = NullSafe.NullSafeString(dataLead?.Loan?.SecondMortgageRateType).Replace("Unknown", "");
                lead.SecondMortgageTerm     = NullSafe.NullSafeInteger(dataLead?.Loan?.SecondMortgageTerm, 0);
                lead.LoanProgramType        = NullSafe.NullSafeString(dataLead?.Loan?.LoanProgramType).Replace("Unknown", "");
                lead.LoanProgramName        = NullSafe.NullSafeString(dataLead?.Loan?.LoanProgramName).Replace("Unknown", "");
                lead.CurrentLender          = NullSafe.NullSafeString(dataLead?.Loan?.CurrentLender).Replace("\n", "").Replace("Your Current Lender", "");
                lead.DateOfLoan             = NullSafe.NullSafeString(dataLead?.Loan?.DateOfLoan);
            }
            if (dataLead.Property != null)
            {
                lead.PropertyAddress       = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Property?.PropertyAddress)).Replace("Unknown", "");
                lead.PropertyAddress2      = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Property?.PropertyAddress2)).Replace("Unknown", "");
                lead.PropertyCity          = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Property?.PropertyCity)).Replace("Unknown", "");
                lead.PropertyCounty        = StringUtilities.PropCase(NullSafe.NullSafeString(dataLead?.Property?.PropertyCounty)).Replace("Unknown", "");
                lead.PropertyDescription   = NullSafe.NullSafeString(dataLead?.Property?.PropertyDescription).Replace("Unknown", "");
                lead.PropertyFound         = NullSafe.NullSafeString(dataLead?.Property?.PropertyFound).Replace("Item", "");
                lead.PropertyNumberOfUnits = NullSafe.NullSafeInteger(dataLead?.Property?.PropertyNumberOfUnits, 0);
                lead.PropertyPurchasedYear = NullSafe.NullSafeInteger(dataLead?.Property?.PropertyPurchasedYear, 0);
                lead.PropertyPurchasePrice = NullSafe.NullSafeInteger(dataLead?.Property?.PropertyPurchasePrice, 0);
                lead.PropertyState         = LocationServices.GetStateAbbreviation(NullSafe.NullSafeString(dataLead?.Property?.PropertyState).Replace("Unknown", "")).ToUpper();
                lead.PropertyType          = NullSafe.NullSafeString(dataLead?.Property?.PropertyType).Replace("Unknown", "");
                lead.PropertyUsage         = NullSafe.NullSafeString(dataLead?.Property?.PropertyUsage).Replace("Unknown", "");
                lead.PropertyValue         = NullSafe.NullSafeInteger(dataLead?.Property?.PropertyValue, 0);
                lead.PropertyYearBuilt     = NullSafe.NullSafeInteger(dataLead?.Property?.PropertyYearBuilt, 0);
                lead.PropertyZip           = NullSafe.NullSafeString(dataLead?.Property?.PropertyZip).Replace("Unknown", "");
            }

            return(lead);
        }
        public void Pristine_Not_Equals_Self_Should_Be_False()
        {
            var pristine = new NullSafe <TestObject>();

            (pristine != pristine).Should().Be(false);
        }
        public void Pristine_Equals_Self_Should_Be_True()
        {
            var pristine = new NullSafe <TestObject>();

            (pristine == pristine).Should().Be(true);
        }
Example #20
0
        private HttpResponseMessage processXmlLead(HttpRequestMessage request, string encryptedClientId, int defaultUserId, string endpoint, bool checkForDuplicate = true)
        {
            this.ResponseFormatter = new XmlMediaTypeFormatter();

            var startTime = DateTime.Now;

            if (string.IsNullOrEmpty(encryptedClientId))
            {
                return(this.CreateErrorResponse(HttpStatusCode.BadRequest, "Missing encrypted client id.", endpoint));
            }

            var     clientId = NullSafe.NullSafeInteger(Encryption.DecryptString(encryptedClientId));
            AClient client   = Master.Lists.Clients.GetClientById(clientId);

            if (!client?.Active ?? true) //if null or not active reject...
            {
                return(this.CreateErrorResponse(HttpStatusCode.Unauthorized, "Client is invalid.", endpoint));
            }

            //http://stackoverflow.com/questions/1127431/xmlserializer-giving-filenotfoundexception-at-constructor
            //Error is thrown here, this is 'expected' beaviour. Just ignore...
            var serializer = new XmlSerializer(typeof(MortgageLead));
            var dataLead   = (MortgageLead)serializer.Deserialize(request.Content.ReadAsStreamAsync().Result);

            ALeadsResponse response = new ALeadsResponse();

            response.ApiEndPoint             = endpoint;
            response.ClientDefinedIdentifier = dataLead.SourceLeadId;

            Lead lead;

            bool doInsert = true;

            if (checkForDuplicate)
            {
                ActionResponse <Lead> actionResponse = this.duplicateCheck(clientId, dataLead);
                if (actionResponse.Success) //true = dupicate
                {
                    doInsert         = false;
                    response.Status  = StatusType.Complete;
                    response.Message = "Duplicate";
                    response.LoanTekDefinedIdentifier = actionResponse.DataObject.Id.ToString();
                }
            }
            if (doInsert && (lead = LegacyLead.ConvertXmlSchema(dataLead)) != null)
            {
                lead.ClientID = clientId;

                //reset UserId to 0 if the User's ClientId does not match this client
                if (lead.UserID > 0 && Users.GetUserById(lead.UserID.GetValueOrDefault())?.ClientId != clientId)
                {
                    lead.UserID = 0;
                }
                if (lead.UserID == 0)
                {
                    lead.UserID = defaultUserId;
                }

                ActionResponse <Lead> actionResponse = new Biz.Contacts.Leads.Objects.Leads(DataContextType.Database, DataConnections.DataContextBankrateWrite).PutWithResponse(lead);
                if (actionResponse.Success)
                {
                    response.Status  = StatusType.Complete;
                    response.Message = Types.Processing.StatusType.Success.ToString();
                    response.LoanTekDefinedIdentifier = actionResponse.DataObject?.Id.ToString();
                }
                else
                {
                    response.Status  = StatusType.Error;
                    response.Message = response.Message;
                }
            }

            response.ExecutionTimeInMillisec = (int)(DateTime.Now - startTime).TotalMilliseconds;
            return(Request.CreateResponse(HttpStatusCode.OK, response, this.ResponseFormatter));
        }