Exemplo n.º 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));
            }
        }
Exemplo n.º 2
0
        private static void ParseSMSRequestAction(SmsRequest request, string actionString, string values)
        {
            //accepted command list (actions)
            switch (actionString.ToLower())
            {
            case "game":
                //values should contain the person's name in this case
                ResponseString = SMSContest.Signup(request, values);
                break;

            case "win":
                ResponseString = SMSContest.Compete(request, values);
                break;


            //SMS "Bot" commands
            case "join":
                DoJoinAction(request, values);
                break;

            case "email":
                DoEmailAction(request, values);
                break;

            case "joke":
                ResponseString = SMSResponseMessages.Joke(request.From);
                break;

            case "cat":
                ResponseString = SMSResponseMessages.NotImplementedMessage(request.From);
                break;

            case "awoo":
            case "aw00":
            case "awooo":
            case "awoooo":
            case "awoo!":
            case "aw00!":
            case "awooo!":
            case "awoooo!":
                ResponseString = SMSResponseMessages.Woof(request.From);
                break;

            case "error":
                //just so I can see the error message sends correctly :)
                ResponseString = SMSResponseMessages.ErrorMessage(request.From);
                break;

            case "stop":
            case "unregister":
                UnregisterPerson(request.From);
                break;

            default:
                ResponseString = SMSResponseMessages.UnknownCommandMessage(request.From);
                break;
            }
        }
Exemplo n.º 3
0
        public static string Signup(SmsRequest request, string values)
        {
            var responseString = string.Empty;

            if (string.IsNullOrEmpty(values))
            {
                return(SMSResponseMessages.MissingValueMessage(request.From, "name", "game Awesome Person #5"));
            }

            return(RegisterPhoneForContest(request.From, values));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Registers an email with the SMS Bot
 /// </summary>
 /// <param name="request"></param>
 /// <param name="values"></param>
 /// <returns></returns>
 private static void DoEmailAction(SmsRequest request, string values)
 {
     if (values == string.Empty)
     {
         ResponseString = SMSResponseMessages.MissingValueMessage(request.From, "email", "email [email protected]");
     }
     else
     {
         var emailUpdated = UpdateEmail(request.From, values);
         if (emailUpdated)
         {
             ResponseString = SMSResponseMessages.CommandsMessage(request.From);
         }
         else
         {
             ResponseString = SMSResponseMessages.ErrorMessage(request.From);
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Joins the SMS Bot
 /// </summary>
 /// <param name="request"></param>
 /// <param name="values"></param>
 /// <returns></returns>
 private static void DoJoinAction(SmsRequest request, string values)
 {
     if (values == string.Empty)
     {
         ResponseString = SMSResponseMessages.MissingValueMessage(request.From, "name", "join Jem Systems");
     }
     else
     {
         var registered = RegisterPhone(request.From, values);
         if (registered)
         {
             ResponseString = SMSResponseMessages.JustRegisteredMessage(request.From);
         }
         else
         {
             ResponseString = SMSResponseMessages.ErrorMessage(request.From);
         }
     }
 }
Exemplo n.º 6
0
        public static string ParseSmsMessage(SmsRequest request)
        {
            var actionString = request.Body.Split(' ').FirstOrDefault().Replace("\"", "");
            var values       = String.Join(" ", (request.Body.Split(' ')).Skip(1));

            if (!IsPhoneRegistered(request.From) && actionString.ToLower() != "join" && actionString.ToLower() != "game" && actionString.ToLower() != "win")
            {
                PhoneInDb = null;
                return(SMSResponseMessages.UnknownPhoneMessage(request.From));
            }

            if (IsPhoneRegistered(request.From) && actionString.ToLower() == "join")
            {
                PhoneInDb = null;
                return(SMSResponseMessages.AlreadyRegisteredMessage(request.From));
            }

            ParseSMSRequestAction(request, actionString.ToLower(), values);

            PhoneInDb = null;

            return(ResponseString);
        }