You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

108 lines
3.0 KiB

using CustomerOnlineV2.Common.Configs;
using Microsoft.AspNetCore.Http;
using System;
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 ShowDecimal2(String strVal)
{
if (strVal != "")
return TruncateDecimalPlaces(decimal.Parse(strVal), 2).Value.ToString("0.00");
else
return strVal;
}
public static decimal? TruncateDecimalPlaces(this decimal? value, int places)
{
if (value == null)
{
return null;
}
return Math.Floor((decimal)value * (decimal)Math.Pow(10, places)) / (decimal)Math.Pow(10, places);
} //
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);
}
}
}