Example #1
0
        public static string UnregisterPerson(string phoneNumber)
        {
            //yea, yea.. there should probably be a flag in this database like 'active' that determines if they're registered... or even a history table that stores the old info so we can delete it from here, but for now this works and I don't lose who has used the system :)
            //large reason for now for saving who has used it - if someone abuses it and starts costing me lots of money, I can track that down easier

            var phoneInDb = GetPhoneEnrollment(phoneNumber);

            if (phoneInDb == null)
            {
                return(SMSResponseMessages.UnknownPhoneMessage(phoneNumber));
            }

            try
            {
                using (var db = new WebAPIDemoSMSContestContext())
                {
                    phoneInDb.Phone       = "Unregistered-" + phoneInDb.Phone;
                    phoneInDb.UpdatedDate = DateTime.Now;
                    db.Enrollments.Attach(phoneInDb);
                    db.Entry(phoneInDb).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    return(SMSResponseMessages.UnregisteredMessage(phoneNumber));
                }
            }
            catch
            {
                return(SMSResponseMessages.ErrorMessage(phoneNumber));
            }
        }
Example #2
0
        public static bool UpdateEmail(string phoneNumber, string email)
        {
            var phoneInDb = GetPhoneEnrollment(phoneNumber);

            if (phoneInDb == null)
            {
                return(false);
            }

            try
            {
                using (var db = new WebAPIDemoSMSContestContext())
                {
                    phoneInDb.Email       = email;
                    phoneInDb.UpdatedDate = DateTime.Now;
                    db.Enrollments.Attach(phoneInDb);
                    db.Entry(phoneInDb).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
Example #3
0
        public static WebAPIDemoContest SetContestStart(int contestId, DateTime contestStart)
        {
            var contest = GetContestWithPeople(contestId);

            if (contest == null)
            {
                return(null);
            }

            try
            {
                using (var db = new WebAPIDemoSMSContestContext())
                {
                    contest.GoLiveTime = contestStart;
                    db.Contests.Attach(contest);
                    db.Entry(contest).State = EntityState.Modified;
                    db.SaveChanges();

                    return(contest);
                }
            }
            catch
            {
                return(null);
            }
        }
Example #4
0
        private static string RegisterPhoneForContest(string phoneNumber, string name, string email = "")
        {
            var contest = GetContestWithPeople(1);

            var demoSMS = contest.PeopleEnrolled.FirstOrDefault(e => e.Phone == phoneNumber);

            if (demoSMS == null)
            {
                demoSMS = SMSDataHelper.GetPhoneEnrollment(phoneNumber);

                if (demoSMS == null)
                {
                    demoSMS = SMSDataHelper.RegisterPhone(phoneNumber, name, email);
                }

                if (demoSMS == null)
                {
                    return("There was an error enrolling you in the contest. Your phone/name could not be added.");
                }


                try
                {
                    using (var db = new WebAPIDemoSMSContestContext())
                    {
                        db.Enrollments.Attach(demoSMS);
                        db.SaveChanges();

                        db.Contests.Attach(contest);
                        contest.PeopleEnrolled.Add(demoSMS);

                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    return("There was an error enrolling you in the contest: " + (ex.Message.Length > 80 ? ex.Message.Substring(0, 80) : ex.Message) + "...");
                }

                return("You're now signed up to play! When you see the text that the contest has begun, reply first with the contest word given for your chance to win!");
            }

            return("Looks like you're already signed up for the contest! Once the key word has been sent out, be first to respond to win!");
        }
Example #5
0
        private static string SetContestEntryAndGetResponse(string phoneNumber, string name)
        {
            var contest = GetContestWithPeople(1);

            var demoSMS = contest.PeopleEnrolled.FirstOrDefault(e => e.Phone == phoneNumber);

            if (demoSMS == null)
            {
                return("Sorry, but it looks like you weren't signed up for the contest... How did you even get the code? :P");
            }

            var sqlDateMinValue = DateTime.Parse("1900-01-01");

            //if not already competed, update to current time
            if (demoSMS.ContestDate == null || demoSMS.ContestDate == sqlDateMinValue)
            {
                demoSMS.ContestDate = DateTime.Now;

                try
                {
                    using (var db = new WebAPIDemoSMSContestContext())
                    {
                        db.Enrollments.Attach(demoSMS);
                        db.Entry(demoSMS).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                }
            }

            var winTime  = demoSMS.ContestDate - contest.GoLiveTime;
            var position = 1;

            foreach (var enrollment in contest.PeopleEnrolled)
            {
                if (enrollment.Phone == demoSMS.Phone)
                {
                    continue;
                }

                if (enrollment.ContestDate < demoSMS.ContestDate && enrollment.ContestDate != null && enrollment.ContestDate != sqlDateMinValue)
                {
                    position++;
                }
            }

            if (position == 1)
            {
                return("Congratulations! Come see Christopher/Sara now to claim your prize! (Must be present to win - prizes given by quickest to respond!)");
            }

            return("Thanks for playing! " + (position - 1) + " " + (position == 2 ? "person" : "people") + " answered before you.");
        }
Example #6
0
        public static WebAPIDemoSMS RegisterPhone(string phoneNumber, string name, string email = "")
        {
            using (var db = new WebAPIDemoSMSContestContext())
            {
                var enrollment = new WebAPIDemoSMS {
                    Name = name, Phone = phoneNumber, CreationDate = DateTime.Now, UpdatedDate = DateTime.Now, Email = (email == "" ? null : email)
                };

                try
                {
                    db.Enrollments.Add(enrollment);
                    db.SaveChanges();

                    return(enrollment);
                }
                catch
                {
                    return(null);
                }
            }
        }