public HttpResponseMessage PostElk(TextMessageView view) { var respons = ElkTextMessage.send(view); var model = view.getModel(); model.created = DateTime.UtcNow; if (respons.StatusCode == HttpStatusCode.OK) { var body = respons.DynamicBody; model.apiId = body.id; model.error = false; model = repo.createTextMessage(model); return(Request.CreateResponse(respons.StatusCode, model)); } else { var message = respons.RawText.Replace("\"", String.Empty); model.error = true; model.errorMessage = message; model = repo.createTextMessage(model); return(Request.CreateResponse(respons.StatusCode, message)); } }
public HttpResponseMessage PostAndContact(MissionView view) { var response = this.Post(view); if (response.StatusCode != HttpStatusCode.OK) { return(response); } var employees = repo.getAllEmployees() .Where(e => e.enabled == true) .Where(e => view.categoryIds.All(c => e.categories.Select(c2 => c2.id).Contains(c))); var models = new List <TextMessageView>(); foreach (var employee in employees) { var messageView = new TextMessageView() { from = "Jobsystems", message = "Hej " + employee.firstName + "!" + "\r\nVi har ett nytt uppdrag till dig:" + "\r\n" + "\r\nDatum: " + view.date.Split('T')[0] + "\r\nTid: " + view.date.Split('T')[1].Substring(0, 5) + "\r\nPlats: " + view.address.street + ", " + view.address.postalCode + " " + view.address.postalTown + "\r\n" + "\r\nLåter detta intressant?", to = employee.phoneNumber, }; var elkResponse = ElkTextMessage.send(messageView); var model = messageView.getModel(); model.created = DateTime.UtcNow; if (elkResponse.StatusCode == HttpStatusCode.OK) { var body = elkResponse.DynamicBody; model.apiId = body.id; model.error = false; model = repo.createTextMessage(model); } else { var message = elkResponse.RawText.Replace("\"", String.Empty); model.error = true; model.errorMessage = message; model = repo.createTextMessage(model); } models.Add(new TextMessageView(model)); } return(response); }
public HttpResponseMessage PostElk(TextMessageView view) { var deliveredUrl = "http://www.adoer.se/api/sms/deliveredelk"; var responseUrl = "http://www.adoer.se/api/sms/recieveelk"; var apiUrl = "https://api.46elks.com/a1/SMS"; var username = "******"; var password = "******"; var data = String.Format("from={0}&to={1}&message={2}&whendelivered={3}$sms_url={4}", view.from, view.to, view.message, deliveredUrl, responseUrl); var http = new EasyHttp.Http.HttpClient(); http.Request.SetBasicAuthentication(username, password); var ans = http.Post(apiUrl, data, HttpContentTypes.ApplicationXWwwFormUrlEncoded); var model = view.getModel(); model.created = DateTime.UtcNow; if (ans.StatusCode == HttpStatusCode.OK) { var body = ans.DynamicBody; model.apiId = body.id; model.error = false; model = repo.createTextMessage(model); return(Request.CreateResponse(ans.StatusCode, model)); } else { var message = ans.RawText.Replace("\"", String.Empty); model.error = true; model.errorMessage = message; model = repo.createTextMessage(model); return(Request.CreateResponse(ans.StatusCode, message)); } }