Beispiel #1
0
        private bool MapRouterUserFromMobileLead(RouterContact user, out RouterUser routerUser2)
        {
            routerUser2 = null;
            GloshareDbContext db = new GloshareDbContext();
            var ml = db.MobilelLeads.FirstOrDefault(v => v.EmailAddress == user.Email);

            if (ml != null)
            {
                {
                    routerUser2 = new RouterUser()
                    {
                        Email    = ml.EmailAddress,
                        First    = ml.Firstname,
                        Last     = ml.Lastname,
                        Address  = ml.Address,
                        City     = ml.City,
                        State    = ml.State,
                        Zip      = ml.Zip,
                        UniqueId = user.UniqueId.ToString(),
                        Gender   = ml.Gender,
                        DOB      = ml.Dob,
                        PrecisionSampleUserID = GetPrecisionSampleUserId(user),
                        RouterContactId       = user.RouterContactId,
                        IpAddress             = ml.Ip
                    };
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        private Surveys  LoadPrecisionSampleSurveys(RouterUser user)
        {
            var             db = new GloshareDbContext();
            PrecisionSample ps = new PrecisionSample();

            Surveys rawSurveys = ps.GetRawSurveys(user).Result;

            List <int> existingProjectIDs = db.RouterSurveyPrecisionSamples.Select(s => s.ProjectId).ToList();

            foreach (SurveysSurvey survey in rawSurveys.Survey)
            {
                if (!existingProjectIDs.Contains((int)survey.ProjectId))
                {
                    RouterSurveyPrecisionSample rsps = new RouterSurveyPrecisionSample()
                    {
                        Name                = survey.SurveyName,
                        ProjectId           = Convert.ToInt32(survey.ProjectId),
                        SurveyLength        = survey.SurveyLength,
                        ConversionRate      = survey.IR,
                        GrossRevenue        = survey.GrossRevenue,
                        RewardValue         = survey.RewardValue,
                        TrafficType         = survey.SurveyTrafficType,
                        Url                 = survey.SurveyUrl,
                        VerityCheckRequired = survey.VerityCheckRequired == "Yes"
                    };
                    db.RouterSurveyPrecisionSamples.Add(rsps);
                    db.SaveChanges();
                }
            }

            return(rawSurveys);
        }
Beispiel #3
0
        internal static IEnumerable <RouterReturn> Map(Surveys psSurveys, RouterUser user)
        {
            //this is mapping the Prescision Sample Raw Result to
            //the RouterReturn

            var returnList = new List <RouterReturn>();

            if (psSurveys?.Survey == null || !psSurveys.Survey.Any())
            {
                return(returnList);
            }

            return(psSurveys.Survey.Select(s =>
                                           new RouterReturn()
            {
                //HostId = (int)RouterHost.PrecisionSample,
                //Name = $"{s.SurveyName}. {s.IR}% success rate ({s.SurveyLength} minutes)",
                Title = s.SurveyName,
                SubTitle = $"{s.SurveyLength} minutes * {s.IR}% success * ${s.RewardValue}",
                //URL = s.SurveyUrl,
                //SuccessRate = s.IR,
                EarningPotential = s.IR * s.RewardValue / s.SurveyLength,
                //ProjectId = s.ProjectId,
                ProxyUrl = GetProxyUrl(user.RouterContactId, RouterHost.PrecisionSample, s.ProjectId, s.SurveyUrl)
            })?.ToList());
        }
Beispiel #4
0
        public static List <RouterReturn> Map(Result yourSurveys, RouterUser user)
        {
            //this is mapping the Your Surveys Raw Result to
            //the RouterReturn

            var returnList = new List <RouterReturn>();

            if (yourSurveys?.surveys == null || !yourSurveys.surveys.Any())
            {
                return(returnList);
            }

            return(yourSurveys.surveys.Select(s =>
                                              new RouterReturn()
            {
                Title = ParseSurveyTitle(s),
                SubTitle = ParseSubTitle(s),
                //loi can be zero so don't divide by 0
                EarningPotential = s.loi == 0 ? 0 : (s.conversion_rate * 100) * (s.cpi * 2) / s.loi,
                ProxyUrl = GetProxyUrl(user.RouterContactId, RouterHost.YourSurvey, s.project_id, s.entry_link)
            })?.ToList());
            //return Ok(new Uri(Request.RequestUri, RequestContext.VirtualPathRoot));
            //returns
            //http://devmapi.cashbackresearch.com/

            //http://devmapi.cashbackresearch.com/api/surveys/SurveyAction?routerContactId=1&hostId=1&projectId=1&surveyUrl=https%3A%2F%2Fwww.your-surveys.com%3Fsi%3D339%26ssi%3DSUBID%26unique_user_id%3D12%26hmac%3D5507767dbc1b2cc4514528c6e47db11e%26offer_id%3D10572805
        }
Beispiel #5
0
        public async Task <Result> GetRawSurveys(RouterUser user)
        {
            var client = new HttpClient();

            // Update port # in the following line.
            client.BaseAddress = new Uri("https://www.your-surveys.com/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Add("x-yoursurveys-api-key", ConfigurationManager.AppSettings["YourSurveysSecretKey"]);

            string dobString = null;

            if (user.DOB != null)
            {
                dobString = user.DOB.Value.ToString("yyyy-MM-dd");
            }

            //"/suppliers_api/surveys/user?user_id=12&date_of_birth=1990-01-01&email=tk%40webhenmedia.com&gender=m&zip_code=68135&ip_address=68.225.172.87&limit=10&basic=1")


            var surveysReturnedLimit = ConfigurationManager.AppSettings["YourSurveysMaxReturned"];

            //var surveysReturnedLimit = "10";
            string uri = $"/suppliers_api/surveys/user?user_id={user.UniqueId}&date_of_birth={dobString}&email={user.Email}&gender={user.Gender}&zip_code={user.Zip}&ip_address={user.IpAddress}&limit={surveysReturnedLimit}&basic=1";
            HttpResponseMessage response = client.GetAsync(uri).Result;


            var content = await response.Content.ReadAsStringAsync();

            Result result = null;

            try
            {
                result = JsonConvert.DeserializeObject <Result>(content);
            }
            catch (Exception e)
            {
                result          = new Result();
                result.status   = "error";
                result.messages = new List <string>()
                {
                    $"Serialization Error From Your Surveys{Environment.NewLine}",
                    e.Message,
                    content
                }.ToArray();
                //Console.WriteLine(e);
                //throw;
            }

            return(result);
        }
Beispiel #6
0
        public string SendSurveyEmail(RouterContact routerContact, out bool error, ListrakRest listrak)
        {
            error = false;
            RouterUser user = null;

            try
            {
                user = GetRouterUser(routerContact.RouterContactId);
            }
            catch (Exception e)
            {
                error = true;
                return(e.ToString());
            }

            //if (user.PrecisionSampleUserID == null)
            //{
            //    error = true;
            //    return $"No precision sample id for {routerContact.Email}";
            //}

            var routerReturnContainer = GetUserSurveys(Guid.Parse(user.UniqueId), user.IpAddress);

            string message = null;

            if (!routerReturnContainer.RouterReturnList.Any())
            {
                error   = true;
                message = $"No surveys found.{Environment.NewLine}{routerReturnContainer.Message}";
                return(message);
            }

            if (routerReturnContainer.RouterReturnList.Count > 2)
            {
                var result = listrak.SendDailySurveysEmail(user, routerReturnContainer.RouterReturnList, out message);
                if (result)
                {
                    return("Email Sent");
                }
            }
            else
            {
                error = true;
                return("Less than 3 surveys. Email not sent.");
            }



            error = true;
            return("Email was not sent successfully. " + message);
        }
Beispiel #7
0
        public bool SendDailySurveysEmail(RouterUser user, List <RouterReturn> surveys, out string message)
        {
            MessageEventBody body = CreateMessageBody(user, surveys);
            Uri uri      = new Uri("https://api.listrak.com/email/v1/List/248553/Contact?eventIds=12598");
            var response = _client.PostAsJsonAsync(uri, body).Result;
            var result   = response.Content.ReadAsStringAsync().Result;

            message = result;

            MailSendReturnStatus status = JsonConvert.DeserializeObject <MailSendReturnStatus>(result);

            if (status.status == 200 || status.status == 201)
            {
                return(true);
            }

            return(false);
        }
Beispiel #8
0
        public Result LoadYourSurveySurveys(RouterUser user)
        {   //Gets the current surveys for this user
            var db = new GloshareDbContext();

            //LoadPrecisionSampleSurveys();

            YourSurvey ys = new YourSurvey();

            var rawSurveyResult = ys.GetRawSurveys(user).Result;

            if (rawSurveyResult.status == "failure" || rawSurveyResult.status == "error")
            {
                rawSurveyResult.surveys = new Survey[0];
                return(rawSurveyResult);
            }

            List <int> existingProjectIDs = db.RouterSurveyYourSurveys.Select(s => s.ProjectId).ToList();

            foreach (Survey survey in rawSurveyResult.surveys)
            {
                if (!existingProjectIDs.Contains((int)survey.project_id))
                {
                    RouterSurveyYourSurvey rsps = new RouterSurveyYourSurvey()
                    {
                        Name               = survey.name,
                        ProjectId          = Convert.ToInt32(survey.project_id),
                        ConversionRate     = Convert.ToDecimal(survey.conversion_rate),
                        Url                = survey.entry_link,
                        Cpi                = Convert.ToDecimal(survey.cpi),
                        Loi                = survey.loi,
                        RemainingCompletes = survey.remaining_completes,
                        StudyType          = survey.study_type
                    };
                    db.RouterSurveyYourSurveys.Add(rsps);
                    db.SaveChanges();
                }
            }

            return(rawSurveyResult);
        }
Beispiel #9
0
        public async Task <Surveys> GetRawSurveys(RouterUser user)
        {
            var client  = new HttpClient();
            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("UserGuid", user.PrecisionSampleUserID.ToString())
            });

            //http://api2.precisionsample.com/v2.asmx/GetSurveys
            var result = client.PostAsync("http://api2.precisionsample.com/v2.asmx/GetSurveys", content).Result;

            XmlSerializer serializer = new XmlSerializer(typeof(string), "http://tempuri.org/");

            string s = null;


            using (Stream stream = await result.Content.ReadAsStreamAsync())
            {
                s = (string)serializer.Deserialize(stream);
            }

            if (s == "<Surveys><Survey>No Surveys were found for your profile.</Survey></Surveys>")
            {
                return(new Surveys()
                {
                    Survey = new SurveysSurvey[0]
                });
            }

            var     innerSerializer = new XmlSerializer(typeof(Surveys));
            Surveys surveyResult    = null;

            using (TextReader reader = new StringReader(s))
            {
                surveyResult = (Surveys)innerSerializer.Deserialize(reader);
            }

            return(surveyResult);
        }
Beispiel #10
0
        public string SendSurveyEmail(string emailAddress, string ipAddress)
        {
            RouterUser user = null;

            try
            {
                user = GetRouterUser(emailAddress);
            }
            catch (Exception e)
            {
                return(e.ToString());
            }

            var routerReturnContainer = GetUserSurveys(Guid.Parse(user.UniqueId), ipAddress);

            //var user = mgr.GetRouterUser(Guid.Parse("B1E269BC-99A5-4B96-A095-06A9CD56D446"));

            var    l = new ListrakRest();
            string message;
            var    result = l.SendDailySurveysEmail(user, routerReturnContainer.RouterReturnList, out message);

            return(result ? "Email Sent" : "Email was not sent successfully. " + message);
        }
Beispiel #11
0
        public RouterReturnContainer GetUserSurveys(Guid userId, string ipAddress)
        {
            //get the common user to send to the survey apis.
            //Since this is coming from the LT Email
            //it's just being made from OIL + RouterContact
            RouterUser user = GetRouterUser(userId);

            user.IpAddress = ipAddress;

            Result yourSurveys = LoadYourSurveySurveys(user);

            RouterReturnContainer returnContainer = new RouterReturnContainer();

            if (yourSurveys.status == "failure")
            {
                returnContainer.Message = yourSurveys.messages[0];
            }
            if (yourSurveys.status == "error")
            {
                returnContainer.Message = string.Join(new string('=', 50) + Environment.NewLine, yourSurveys.messages);
            }

            List <RouterReturn> ysReturns = Mapper.Map(yourSurveys, user);

            if (!yourSurveys.surveys.Any())
            {
                return(returnContainer);
            }

            //Surveys psSurveys = LoadPrecisionSampleSurveys(user);
            //ysReturns.AddRange(Mapper.Map(psSurveys, user));

            var sorted = ysReturns.OrderByDescending(y => y.EarningPotential).ToList();

            returnContainer.RouterReturnList = sorted;
            return(returnContainer);
        }
Beispiel #12
0
        private MessageEventBody CreateMessageBody(RouterUser user, List <RouterReturn> surveys)
        {
            RouterReturn survey1 = surveys.First();
            RouterReturn survey2 = surveys.Skip(1).Take(1).First();
            RouterReturn survey3 = surveys.Skip(2).Take(1).First();

            var survey1Reward = survey1.SubTitle.Split('*').ToList().Last();

            MessageEventBody body = new MessageEventBody();

            body.emailAddress            = user.Email;
            body.subscriptionState       = "Subscribed";
            body.segmentationFieldValues = new Segmentationfieldvalue[]
            {
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.firstname, value = user.First
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveyreward1, value = survey1Reward
                },

                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveylink1, value = survey1.ProxyUrl
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveyname1, value = survey1.Title
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveystats1, value = survey1.SubTitle
                },

                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveylink2, value = survey2.ProxyUrl
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveyname2, value = survey2.Title
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveystats2, value = survey2.SubTitle
                },

                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveylink3, value = survey3.ProxyUrl
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveyname3, value = survey3.Title
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveystats3, value = survey3.SubTitle
                },

                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.dailysurveyslink, value = $"{ConfigurationManager.AppSettings["DailySurveysLink"]}{user.UniqueId}"
                },

                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.surveyquantity, value = (surveys.Count - 1).ToString()
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.date, value = DateTime.Today.ToLongDateString()
                },
                new Segmentationfieldvalue()
                {
                    segmentationFieldId = (int)DaileySurveyFields.time, value = $"{DateTime.Now:hh:mm tt}"
                }
            };

            return(body);
        }
Beispiel #13
0
        private bool MapRouterUserFromOil(RouterContact user, out RouterUser routerUser1)
        {
            routerUser1 = null;
            GloshareDbContext db = new GloshareDbContext();
            var oils             = db.VwOptInLeadSurveys.Where(v => v.EmailAddress == user.Email).OrderByDescending(o => o.OptInDate);

            if (oils.Any())
            {
                if (oils.Count() == 1 || oils.Count() > 2)
                {
                    var oil = oils.First();
                    routerUser1 = new RouterUser()
                    {
                        Email    = oil.EmailAddress,
                        First    = oil.Firstname,
                        Last     = oil.Lastname,
                        Address  = oil.Address,
                        City     = oil.City,
                        State    = oil.State,
                        Zip      = oil.Zip,
                        UniqueId = user.UniqueId.ToString(),
                        Gender   = GetGender(oil.Gender),
                        DOB      = GetBirthDate(oil.BirthdayDay, oil.BirthdayMonth, oil.BirthdayYear),
                        PrecisionSampleUserID = GetPrecisionSampleUserId(user),
                        RouterContactId       = user.RouterContactId,
                        IpAddress             = oil.Ip
                    };
                    return(true);
                }
                //merge the 2
                bool second            = false;
                VwOptInLeadSurvey oil1 = oils.First();
                VwOptInLeadSurvey oil2 = null;
                foreach (VwOptInLeadSurvey optInLeadSurvey in oils)
                {
                    if (second)
                    {
                        oil2 = optInLeadSurvey;
                    }

                    second = true;
                }
                //var oil2 = oils.Last();  This doesn't work for some reason so loop thing above
                routerUser1 = new RouterUser()
                {
                    Email    = oil1.EmailAddress,
                    First    = oil1.Firstname ?? oil2.Firstname,
                    Last     = oil1.Lastname ?? oil2.Lastname,
                    Address  = oil1.Address ?? oil2.Address,
                    City     = oil1.City ?? oil2.City,
                    State    = oil1.State ?? oil2.State,
                    Zip      = oil1.Zip ?? oil2.Zip,
                    UniqueId = user.UniqueId.ToString(),
                    Gender   = GetGender(oil1.Gender ?? oil2.Gender),
                    DOB      = GetBirthDate(oil1.BirthdayDay ?? oil2.BirthdayDay, oil1.BirthdayMonth ?? oil2.BirthdayMonth, oil1.BirthdayYear ?? oil2.BirthdayYear),
                    PrecisionSampleUserID = GetPrecisionSampleUserId(user),
                    RouterContactId       = user.RouterContactId,
                    IpAddress             = oil1.Ip //?? oil2.Ip
                };
                return(true);
            }

            return(false);
        }