public MessageResource SendTextMessage(string gameName) { string user = User.Identity.Name; Phone phone = new Phone(); using (PhoneDataContext db = new PhoneDataContext()) { bool exists = db.Phones.Any(m => m.UserName == user); if (exists) { phone = db.Phones.First(m => m.UserName == user); } else { return(null); } } // Text user if they have notifications enabled if (phone.ReceiveTexts) { RestClient rc = new RestClient(); string to = "+1" + phone.PhoneNumber; string body = "This week you will be playing " + gameName + "!"; return(rc.SendMessage("+12562692445", to, body, null).Result); } return(null); }
public JsonResult GetPhone() { string user = User.Identity.Name; // Check if user has a phone number listed using (PhoneDataContext db = new PhoneDataContext()) { bool exists = db.Phones.Any(m => m.UserName == user); if (exists) // Phone number exists so delete it and add the new one { Phone phone = db.Phones.First(m => m.UserName == user); if (phone != null) { var jsonPhone = "{"; jsonPhone += "\"success\": true,"; jsonPhone += "\"phone_number\": " + phone.PhoneNumber + ","; jsonPhone += "\"receive_texts\": " + phone.ReceiveTexts.ToString().ToLower() + "}"; return(Json(jsonPhone, JsonRequestBehavior.AllowGet)); } } } return(Json("{\"success\": false}", JsonRequestBehavior.AllowGet)); }
public JsonResult UpdatePhone(string phoneNum, bool receiveTexts) { if (Regex.IsMatch(phoneNum, @"^([0-9]{3})([0-9]{3})([0-9]{4})$")) { string user = User.Identity.Name; // Check if user has a phone number listed using (PhoneDataContext db = new PhoneDataContext()) { bool exists = db.Phones.Any(m => m.UserName == user); if (exists) // Phone number exists so delete it and add the new one { Phone phone = db.Phones.First(m => m.UserName == user); if (phone != null) { db.Phones.Remove(phone); Phone newPhone = new Phone(); newPhone.UserName = user; newPhone.PhoneNumber = phoneNum; newPhone.ReceiveTexts = receiveTexts; db.Phones.Add(newPhone); db.SaveChanges(); return(Json("{\"success\": true}", JsonRequestBehavior.AllowGet)); } } else // No phone number listed so add a new one { Phone newPhone = new Phone(); newPhone.UserName = user; newPhone.PhoneNumber = phoneNum; newPhone.ReceiveTexts = receiveTexts; db.Phones.Add(newPhone); db.SaveChanges(); return(Json("{\"success\": true}", JsonRequestBehavior.AllowGet)); } } return(Json("{\"success\": true}", JsonRequestBehavior.AllowGet)); } return(Json("{\"success\": false}", JsonRequestBehavior.AllowGet)); }
public PhoneEntryRepository() { _context = new PhoneDataContext(); _context.DeferredLoadingEnabled = true; _context.ObjectTrackingEnabled = true; }