Example #1
0
        public async Task <bool> SendSMS(SMSInformation smsContent)
        {
            bool status = await _iSmsConnectorService.SendSMS(smsContent);

            if (status == true)
            {
                _iSmsRepository.Insert(smsContent);
            }
            return(status);
        }
Example #2
0
        public async Task <int> Send(SmsDto dto)
        {
            int statusCode = 400;

            try
            {
                string url = $"{_credential.ApiUrl}?Username={_credential.Username}&Password={_credential.Password}&From={_credential.From}&To=88{dto.MobileNumber}&Message={dto.Message}";
                using (var response = await HttpHelper.SendRequest(HttpMethod.Get, url))
                {
                    var result = await response.Content.ReadAsStringAsync();

                    if (response.IsSuccessStatusCode)
                    {
                        var serializer = new XmlSerializer(typeof(ArrayOfServiceClass));
                        using (TextReader reader = new StringReader(result))
                        {
                            var res = (ArrayOfServiceClass)serializer.Deserialize(reader);
                            if (res.ServiceClass.StatusText == "success")
                            {
                                statusCode = 200;
                            }
                            string json = JsonConvert.SerializeObject(res);
                            await _repository.Insert(dto.MobileNumber, dto.Message, (int)response.StatusCode, dto.AppId, responseJson : json);
                        }
                    }
                    else
                    {
                        await _repository.Insert(dto.MobileNumber, dto.Message, (int)response.StatusCode, dto.AppId, result);
                    }
                }
            }
            catch (Exception ex)
            {
                await _repository.Insert(dto.MobileNumber, dto.Message, statusCode, dto.AppId, ex.ToString());
            }
            return(await Task.FromResult(statusCode));
        }