public async Task <ActionResult> Survey(SurveyViewModel vm) { if (ModelState.IsValid) { var survey = context.Surveys.Where(s => s.SurveyId == vm.SurveyId).FirstOrDefault(); if (survey == null) { var client = new TwilioRestClient(ConfigurationManager.AppSettings["AccountSid"], ConfigurationManager.AppSettings["AuthToken"]); #if DEBUG var result = client.AddIncomingLocalPhoneNumber(new PhoneNumberOptions() { PhoneNumber = vm.PhoneNumber, SmsUrl = "http://example.com/Phone/Store", VoiceUrl = "" }); #else var result = client.AddIncomingLocalPhoneNumber(new PhoneNumberOptions() { PhoneNumber = vm.PhoneNumber, SmsUrl = Url.Action("Store", "Phone", null, "http"), VoiceUrl = "" }); #endif if (result.RestException != null) { throw new Exception(string.Format("Unable to add phone number: \"{0}\"", result.RestException.Message)); } survey = new Survey(); survey = context.Surveys.Add(survey); } survey.PhoneNumber = vm.PhoneNumber; survey.ResponseText = vm.ResponseText; survey.IsEnabled = vm.IsEnabled; survey.UpdatedAt = DateTime.Now; await context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(vm)); }