public TwiMLResult Incoming(string from, string body) { string response; Subscriber subscriber = _db.Subscribers.FirstOrDefault(s => s.PhoneNumber == from); if (subscriber == null) { // If subscriber not found, create new subscriber and return signup prompt. subscriber = _db.Subscribers.Add(new Subscriber { PhoneNumber = from }); response = "Thanks for contacting us! Text 'subscribe' if you would like to receive updates via text message."; } else { // Otherwise, process the message for existing subscriber. response = ProcessMessage(body.ToLower(), subscriber); } // Save any changes made to the Subscriber to the database _db.SaveChanges(); // Generate and return TwiML response return(GenerateTwiML(response)); }
public Subscriber Add(Subscriber entity) { try { context.Subscribers.Add(entity); context.SaveChanges(); return(GetById(entity.Id)); } catch (Exception) { throw; } }