public static Customer GetCustomer(int customerID, bool realtime = false) { if (!MemoryCache.Default.Contains("Customer_" + customerID)) { Customer customer = null; if (!realtime) { using (var context = ExigoDAL.Sql()) { customer = context.Query <Customer, Address, Address, Address, Customer>(@" SELECT c.CustomerID ,c.FirstName ,c.MiddleName ,c.LastName ,c.NameSuffix ,c.Company ,c.CustomerTypeID ,c.CustomerStatusID ,c.Email ,c.Phone AS PrimaryPhone ,c.Phone2 AS SecondaryPhone ,c.MobilePhone ,c.Fax ,c.CanLogin ,c.LoginName ,c.PasswordHash ,c.RankID ,c.EnrollerID ,c.SponsorID ,c.BirthDate ,c.CurrencyCode ,c.PayableToName ,c.DefaultWarehouseID ,c.PayableTypeID ,c.CheckThreshold ,c.LanguageID ,c.Gender ,c.TaxCode AS TaxID ,c.TaxCodeTypeID ,c.IsSalesTaxExempt ,c.SalesTaxCode ,c.SalesTaxExemptExpireDate ,c.VatRegistration ,c.BinaryPlacementTypeID ,c.UseBinaryHoldingTank ,c.IsInBinaryHoldingTank ,c.IsEmailSubscribed ,c.EmailSubscribeIP ,c.Notes ,c.Field2 ,c.Field3 ,c.Field4 ,c.Field5 ,c.Field6 ,c.Field7 ,c.Field8 ,c.Field9 ,c.Field10 ,c.Field11 ,c.Field12 ,c.Field13 ,c.Field14 ,c.Field15 ,c.Date1 ,c.Date2 ,c.Date3 ,c.Date4 ,c.Date5 ,c.CreatedDate ,c.ModifiedDate ,c.CreatedBy ,c.ModifiedBy ,cs.CustomerStatusDescription ,ct.CustomerTypeDescription ,c.MainAddress1 AS Address1 ,c.MainAddress2 AS Address2 ,c.MainAddress3 AS Address3 ,c.MainCity AS City ,c.MainState AS State ,c.MainZip AS Zip ,c.MainCountry AS Country ,c.MainCounty AS County ,c.MainVerified AS isVerified ,c.MailAddress1 AS Address1 ,c.MailAddress2 AS Address2 ,c.MailAddress3 AS Address3 ,c.MailCity AS City ,c.MailState AS State ,c.MailZip AS Zip ,c.MailVerified AS isVerified ,c.MailCountry AS Country ,c.MailCounty AS County ,c.OtherAddress1 AS Address1 ,c.OtherAddress2 AS Address2 ,c.OtherAddress3 AS Address3 ,c.OtherCity AS City ,c.OtherState AS State ,c.OtherZip AS Zip ,c.OtherCountry AS Country ,c.OtherCounty AS County ,c.OtherVerified AS isVerified FROM Customers c LEFT JOIN CustomerStatuses cs ON c.CustomerStatusID = cs.CustomerStatusID LEFT JOIN CustomerTypes ct ON c.CustomerTypeID = ct.CustomerTypeID WHERE c.CustomerID = @CustomerID ", (cust, main, mail, other) => { main.AddressType = AddressType.Main; cust.MainAddress = main; mail.AddressType = AddressType.Mailing; cust.MailingAddress = mail; other.AddressType = AddressType.Other; cust.OtherAddress = other; return(cust); }, param: new { CustomerID = customerID }, splitOn: "Address1, Address1, Address1" ).FirstOrDefault(); } } if (customer == null) { var customerResponse = ExigoDAL.WebService().GetCustomers(new GetCustomersRequest { CustomerID = customerID }).Customers.FirstOrDefault(); customer = (Customer)customerResponse; customer.RankID = customerResponse.RankID; customer.CustomerStatusDescription = CommonResources.CustomerStatuses(customerResponse.CustomerStatus); } if (customer == null) { return(null); } MemoryCache.Default.Add("Customer_" + customerID, customer, DateTime.Now.AddMinutes(15)); return(customer); } else { return(MemoryCache.Default.Get("Customer_" + customerID) as Customer); } }