// TODO: external token/auth key - possibly public async Task <IActionResult> Api([Bind("ID,From,To,Body,AccountSid,ToCountry,ToState,SmsMessageSid,NumMedia,ToCity,FromZip,SmsSid,FromState,SmsStatus,FromCity,FromCountry,ToZip,NumSegments,MessageSid,ApiVersion")] IncomingMessage incomingMessage) { // default repsonse, in case no incoming POST data can be processed string textMessage = "Internal error. This is default fallback message."; // store incoming POST data bound to model object in context if (ModelState.IsValid) { // add incoming data as IncomingMessage record to database _context.Add(incomingMessage); await _context.SaveChangesAsync(); // new Jumble - and internally construct MessageOut Jumble jumble = new Jumble(incomingMessage); _context.Add(jumble); await _context.SaveChangesAsync(); // set response content textMessage = jumble.MessageOut; } // construct TwiML from to be returned message MessagingResponse twiml = new MessagingResponse(); twiml.Message(textMessage); string twixml = twiml.ToString(); // output TwiML xml or plain output format return(Content(textMessage)); }
public async Task <IActionResult> Create([Bind("ID,MessageIn,MessageOut,NumberTo,NumberFrom,TimeStamp")] Jumble jumble) { if (ModelState.IsValid) { _context.Add(jumble); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(jumble)); }