public async Task <string> SendSmsAsync(string mobileNo, string msg, string email, string otp = null, string sentFlag = null) { string returnValue; string weblink = $"http://80.241.215.220/sendsms/sendsms.php?username=EIkumuni&password=tech321&type=TEXT&sender=KUMUNI&mobile={mobileNo}&message={msg}"; try { var response = await httpClient.GetAsync(weblink); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); string[] messageContent = content.Split('|'); if (sentFlag.ToLower() == "resend") { returnValue = "success"; } else { var allOtpData = await dapperService.GetOtpDetailsAsync(); var otpData = allOtpData.FirstOrDefault(f => f.Email.ToLower() == email.ToLower() && f.IsValid == false); if (otpData == null) { var otpModel = new OtpTable() { UniqueId = Guid.NewGuid().ToString().GetHashCode().ToString("x"), Email = email, Message = messageContent[0].Trim(), Otp = string.IsNullOrEmpty(otp) ? string.Empty : otp }; returnValue = await dapperService.InsertOtpDetailsAsync(otpModel); } else { returnValue = "success"; } } return(returnValue); } } catch (Exception ex) { return("failure"); // return ex.Message; } return("failure"); }
public async Task <string> InsertOtpDetailsAsync(OtpTable otpTable) { string returnValue; var otpModel = new { uniueId = otpTable.UniqueId, otp = otpTable.Otp, email = otpTable.Email, message = otpTable.Message }; string sql = @"Insert into OtpTableMaster(UniqueId, Otp, Email, Message, TimeStamp) values(@uniueId, @otp, @email, @message, GetDate())"; using (IDbConnection connection = new SqlConnection(configuration.GetConnectionString("DefaultConnection"))) { if (connection.State == ConnectionState.Open) { connection.Close(); } connection.Open(); using (IDbTransaction transaction = connection.BeginTransaction()) { try { var result = await connection.ExecuteAsync(sql, otpModel, transaction); if (result > 0) { returnValue = "success"; transaction.Commit(); } else { returnValue = "failure"; transaction.Rollback(); } } catch (Exception e) { transaction.Rollback(); returnValue = "failure"; // returnValue = e.Message; } } } return(returnValue); }