public async Task <OutputResponse> SendMessage(MessageModel message) { var result = new OutputResponse { IsErrorOccured = false }; if (message != null) { var url = string.Format("{0}?username={1}&password={2}&to={3}&smsc={4}&from={5}&text={6}", _smsConfiguration.BaseUrl, _smsConfiguration.RapidProUserName, _smsConfiguration.RapidProPassword, message.DestinationRecipients.FirstOrDefault(), _smsConfiguration.RapidProSmsCode, _smsConfiguration.SmsSender, message.MessageBody); var response = await HttpRequestFactory.Get(url); if (response.StatusCode == HttpStatusCode.Accepted) { result.Message = "Message Queued for delivery"; } else { result.Message = "Sending of message failed"; result.IsErrorOccured = true; } } else { result.IsErrorOccured = true; result.Message = "Message model cannot be null or empty"; } return(result); }
public OutputResponse getToken(string strClientId, string strClientSecret, string strGrantType, string strResource, string strSubcription) { OutputResponse objOutRes = null; try { string URL = "https://login.microsoftonline.com/" + ConfigurationManager.AppSettings["ida:AuthTokenTenant"] + "/oauth2/token"; var client = new RestClient(URL); var request = new RestRequest(Method.POST); request.AddHeader("Ocp-Apim-Subscription-Key", strSubcription); request.AddParameter("grant_type", strGrantType); request.AddParameter("client_id", strClientId); request.AddParameter("client_secret", strClientSecret); request.AddParameter("resource", strResource); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { objOutRes = JsonConvert.DeserializeObject <OutputResponse>(response.Content); } else { objOutRes = JsonConvert.DeserializeObject <OutputResponse>(response.Content); } } catch (Exception e) { objOutRes = new OutputResponse(); objOutRes.ErrMsg = e.Message; return(objOutRes); } return(objOutRes); }
public IHttpActionResult GetOTP(MobileOtpDetails mobileDetails) { try { var isSaveUpdate = _iMobileApiCore.SaveUpdateMobileOtp(mobileDetails); var outputResponse = new OutputResponse() { IsSuccess = isSaveUpdate }; var response = new Message <OutputResponse>() { StatusCode = "200", ReturnMessage = "Success", Data = outputResponse }; return(Ok(response)); } catch (Exception ex) { var response = new Message <OutputResponse>() { StatusCode = "400", ReturnMessage = ex.Message }; return(Ok(response)); } }
public async Task <OutputResponse> SendMessage(MessageModel message) { var result = new OutputResponse { IsErrorOccured = false }; var hasRecipient = false; var emailMessage = new BulkMessage(); emailMessage.Subject = message.Subject; emailMessage.HtmlBody = message.MessageBody; emailMessage.From.Email = message.SourceAddress; foreach (var recipient in message.DestinationRecipients) { if (!string.IsNullOrEmpty(recipient)) { emailMessage.To.Add(recipient); hasRecipient = true; } } // Only send email if they are actual recipients if (hasRecipient) { await _client.SendAsync(emailMessage); result.Message = "Email sent successfully"; } else { result.Message = "No emails could be found"; } return(result); }
internal Task SendResponseAsync(OutputResponse response, CancellationToken cancellationToken = default) { return(this.SendResponseAsync(response, () => { return this.Dialog.SendResponseAsync(response, cancellationToken); })); }
internal void SendResponse(OutputResponse response) { this.SendResponse(response, () => { this.Dialog.SendResponse(response); }); }
public HttpResponseMessage SavePostPayment(PaymentModule paymentModule) { var paymentResponse = _iPaymentsCore.PostSavePayment(paymentModule); var output = new OutputResponse() { IsSuccess = paymentResponse }; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, output); return(response); }
public async Task <OutputResponse> GetNationalStatistics() { var result = new OutputResponse { IsErrorOccured = false }; var statistics = default(DhisNationalStatisticsDTO); try { var endpoint = string.Concat(_baseUrl, "aggregates"); var response = await HttpRequestFactory.Get(endpoint, TimeSpan.FromMilliseconds(1500)); if (response.IsSuccessStatusCode) { statistics = response.ContentAsType <DhisNationalStatisticsDTO>(); // store in cache await _database.AddAsync("national-stats", statistics, flag : CommandFlags.FireAndForget); } else { if (await _database.ExistsAsync("national-stats")) { statistics = await FromCache(); } else { result.IsErrorOccured = true; } } } catch (Exception) { statistics = await FromCache(); } finally { result.Result = statistics; } return(result); }
public async Task <OutputResponse> GetList() { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://api.worldbank.org"); using (var response = client.GetAsync("v2/country/all/indicator/NY.GDP.MKTP.CD?date=2018&per_page=500&format=json").Result) { if (response.IsSuccessStatusCode) { response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); //get the array object var arrayResponse = JsonConvert.DeserializeObject <object[]>(result.ToString()); send = new OutputResponse { PagingDetail = JsonConvert.DeserializeObject <PagingDetail>(arrayResponse[0].ToString()), Data = JsonConvert.DeserializeObject <List <Data> >(arrayResponse[1].ToString()) }; } else if (!response.IsSuccessStatusCode) { throw new Exception((int)response.StatusCode + "-" + response.StatusCode.ToString()); } } } } catch (Exception e) { var p = e.Message; } return(send); }
protected Task SendResponseAsync(OutputResponseStatus status, CancellationToken cancellationToken = default) { OutputResponse response = this.CreateResponse(status); return(this.Workflow.SendResponseAsync(response, cancellationToken)); }
protected void SendResponse(OutputResponseStatus status) { OutputResponse response = this.CreateResponse(status); this.Workflow.SendResponse(response); }
public async Task <OutputResponse> RegisterUserAsync(UserDTO userDTO) { var password = ""; var response = new OutputResponse { IsErrorOccured = true }; try { using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { RandomPasswordGenerator randomPasswordGenerator = new RandomPasswordGenerator(); password = randomPasswordGenerator.GeneratePassword(true, true, true, true, 8); var newUser = new ApplicationUser { UserName = userDTO.PhoneNumber, NormalizedUserName = userDTO.PhoneNumber, DefaultPassword = 0 }; newUser.PasswordHash = new PasswordHasher <ApplicationUser>().HashPassword(newUser, password); await _userManager.CreateAsync(newUser); var user = await _userManager.FindByNameAsync(newUser.UserName); IList <Claim> userClaimList = new List <Claim>(); userClaimList.Add(new Claim("name", user.UserName)); userClaimList.Add(new Claim("full_name", userDTO.FullName)); await _userManager.AddClaimsAsync(user, userClaimList); response = new OutputResponse { IsErrorOccured = false, Result = password }; scope.Complete(); } } catch (TransactionAbortedException) { response = new OutputResponse { IsErrorOccured = true, Message = "An error occured while trying to create your user account, try again" }; } catch (ApplicationException) { response = new OutputResponse { IsErrorOccured = true, Message = "An error occured while trying to create your user account, try again" }; } var message = $"You have been successfully registered as a team member on the" + $" Thandizo web portal. Here is your default password: {password} \n" + $"Login in at https://portal.thandizo.mw"; if (!response.IsErrorOccured) { await _smsService.SendSmsAsync(userDTO.PhoneNumber, password); } return(response); }
public static string Process(HttpResponseMessage httpResponse) { string friendlyMessage = "ResponceSystemError"; var outputResponse = new OutputResponse(); try { //try to convert the returned object to see it an output handler outputResponse = httpResponse.ContentAsType <OutputResponse>(); } catch (Exception) { //it means it failed to convert to OutputResponse object, set to NULL outputResponse = null; } if (outputResponse != null) { if (!string.IsNullOrEmpty(outputResponse.Message)) { friendlyMessage = httpResponse.ContentAsType <OutputResponse>().Message; } } else //return type not OutputResponse { try { var response = httpResponse.Content.ReadAsStringAsync().Result.ToString(); friendlyMessage = response.Replace("\"", ""); if (String.IsNullOrEmpty(friendlyMessage)) { friendlyMessage = httpResponse.ReasonPhrase.ToString(); } } catch (Exception) { //provide generic and friendly responses to the client switch (httpResponse.StatusCode) { case HttpStatusCode.BadGateway: friendlyMessage = "BadGatewayError"; break; case HttpStatusCode.Unauthorized: friendlyMessage = "UnauthorizedError"; break; case HttpStatusCode.NotFound: friendlyMessage = "NotFoundError"; break; case HttpStatusCode.Accepted: friendlyMessage = "AcceptedResponse"; break; case HttpStatusCode.Forbidden: friendlyMessage = "ForbiddenError"; break; case HttpStatusCode.InternalServerError: friendlyMessage = "InternalServerError"; break; case HttpStatusCode.ServiceUnavailable: friendlyMessage = "ServiceUnavailable"; break; case HttpStatusCode.BadRequest: friendlyMessage = "BadRequest"; break; } } } return(friendlyMessage); }
public Task SendResponseAsync(OutputResponse response, CancellationToken cancellationToken = default) { return(base.SendResponseAsync(response, cancellationToken)); }
public void SendResponse(OutputResponse response) { base.SendResponse(response); }