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!"); }
/// <summary> /// Registers a person's phone information through entity /// </summary> /// <param name="phoneNumber"></param> /// <param name="name"></param> /// <param name="email"></param> /// <returns></returns> private static bool RegisterPhone(string phoneNumber, string name, string email = "") { return(SMSDataHelper.RegisterPhone(phoneNumber, name, email) != null); }