using CustomerOnlineV2.Common.Configs; using Microsoft.AspNetCore.Http; using System.Text.RegularExpressions; namespace CustomerOnlineV2.Common.Helper { public static class Utilities { public static string GetIpAddressv2(HttpContext httpContext) { var ipDetails = httpContext.Connection.RemoteIpAddress; return ipDetails.ToString(); } public static string ReadAppSettings(string key) { return ConfigurationManager.AppSettings[key]; } public static string ReadFromAppSettings(string key, string defValue = "") { return ConfigurationManager.AppSettings[key] ?? defValue; } public static decimal TryParseDecimal(string amount) { decimal output; decimal.TryParse(amount, out output); return output; } public static string GetRowCellValue(object v) { try { if (v == DBNull.Value) return ""; else return v.ToString(); } catch (Exception) { return ""; } } public static int GetRowCellValueInt(object v) { try { if (v == DBNull.Value) return 101; else return Convert.ToInt32(v); } catch (Exception) { return 101; } } public static string ShowDecimal(string strVal) { if (strVal != "") return string.Format("{0:0,0.00}", double.Parse(strVal)); else return strVal; } public static string GenerateOTP() { string[] strChar = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; Random random = new Random(); string otpChar = strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)] + strChar[random.Next(0, 10)]; return otpChar; } public static bool IsValidEmail(this string email) { return Regex.IsMatch(email ?? "", ApplicationConfig.ReadWebConfig("regex"), RegexOptions.IgnoreCase); } } }