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)); } }
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); } }
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); } }
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."); }