LittleDemon WebShell


Linux hosting5.siteguarding.com 3.10.0-962.3.2.lve1.5.88.el7.x86_64 #1 SMP Fri Sep 26 14:06:42 UTC 2025 x86_64
Path : /home/devsafetybis/.trash/yuvatrip.com/App_Code/
File Upload :
Command :
Current File : /home/devsafetybis/.trash/yuvatrip.com/App_Code/commonfunctions.cs

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using System.IO.Compression;
using System.Collections;
using System.Security.Cryptography;

/// <summary>
/// Summary description for CommonFunctions
/// </summary>
/// 

namespace YT.Common
{


    
    public static class commonfunctions
    {
        
        //public static dynamic GetDynamicData(dynamic criteria, string querystring, CommandType commandtype)
        //{
        //    dynamic data = new ExpandoObject();
        //    dynamic status = new ExpandoObject();
        //    dynamic response = new ExpandoObject();
            
        //    try
        //    {
        //        SqlCommand Command = new SqlCommand();
        //        Command.CommandText = querystring;
        //        foreach (KeyValuePair<string, object> pair in criteria)
        //        {  Command.Parameters.Add(new SqlParameter("@" + pair.Key, pair.Value)); }

        //        string  responsestring = new DatabaseConnection(DatabaseDetail.localhost).ExeNonQuery(Command, CommandType.Text);
                
        //        if (!String.IsNullOrEmpty(responsestring) && !String.IsNullOrWhiteSpace(responsestring))
        //        { 
        //            response = JsonConvert.DeserializeObject<ExpandoObject>(responsestring);
        //            data.response = response;
        //            status.errorcode = 0;
        //            status.errormessage = "No error.";
        //        }
        //        else
        //        { 
        //            data.response = "blank";
        //            status.errorcode = 1;
        //            status.errormessage = "No Data Found.";
        //        }

        //    }
        //    catch (Exception exception)
        //    {
        //        status.errorcode = 100;
        //        status.errormessage = exception.Message;
        //    }
        //    finally
        //    {
        //        data.status = status;
        //    }
        //    return data;
        //}

        public static class GlobalVariables
    {
       
        public static dynamic TokenId = read();
        public static dynamic read()
        {
            dynamic reader;

            try
            {

                using (FileStream fs = File.Open(HttpContext.Current.Server.MapPath("~/app_code/") + "authorization.json", FileMode.Open))
                using (StreamReader sw = new StreamReader(fs))
                using (var jw = new JsonTextReader(sw))
                {
                    JsonSerializer se = new JsonSerializer();
                    reader = se.Deserialize<ExpandoObject>(jw);
                }

            }
            catch (Exception exception)
            {
                return exception.Message;
            }

            return reader.run.executions[0].response.body;
        }
    }
        public static dynamic GetSetDynamicData(dynamic dynamicobj,dynamic criteria, string querystring, CommandType commandtype, string database = "localhost")
        {
            dynamic data = new ExpandoObject();
            dynamic status = new ExpandoObject();
            dynamic response = new ExpandoObject();

            try
            {
                string json = "";
                SqlCommand Command = new SqlCommand();
                DataTable Table = new DataTable();
                Command.CommandText = querystring;

                if (dynamicobj != null)
                { 
                     var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    Type t = dynamicobj.GetType();
                    bool isDict = t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Dictionary<,>);

                    if(isDict) { json= javaScriptSerializer.Serialize(dynamicobj); }
                    else { json = javaScriptSerializer.Serialize(((ExpandoObject)dynamicobj).ToDictionary(item => item.Key, item => item.Value)); }
                    Command.Parameters.Add(new SqlParameter("@json", json));
                }
                

                if (criteria != null)
                { 
                    foreach (KeyValuePair<string, object> pair in criteria)
                    { Command.Parameters.Add(new SqlParameter("@" + pair.Key, pair.Value)); }
                }
                string responsestring = "";
                if (database == "localhost")
                    responsestring = new DatabaseConnection(DatabaseDetail.localhost).ExeNonQuery(Command, CommandType.StoredProcedure);
                else
                    responsestring = new DatabaseConnection(DatabaseDetail.YuvatripDB).ExeNonQuery(Command, CommandType.StoredProcedure);
                if (!String.IsNullOrEmpty(responsestring) && !String.IsNullOrWhiteSpace(responsestring))
                {
                    response = JsonConvert.DeserializeObject<ExpandoObject>(responsestring);
                    data.response = response;
                    status.errorcode = 0;
                    status.errormessage = "No error.";
                }
                else
                {
                    data.response = "blank";
                    status.errorcode = 1;
                    status.errormessage = "No Data Found.";
                }
            }
            catch (Exception exception)
                {
                status.errorcode = 100;
                status.errormessage = exception.Message;
            }
            finally
            {
                data.status = status;
            }
            return data;
        }
        public static dynamic getsetdynamicdata(dynamic dynamicobj,dynamic criteria, string querystring, CommandType commandtype, string database = "localhost")
        {
            dynamic data = new ExpandoObject();
            dynamic status = new ExpandoObject();
            dynamic response = new ExpandoObject();

            try
            {
                string json = "";
                SqlCommand Command = new SqlCommand();
                DataTable Table = new DataTable();
                Command.CommandText = querystring;

                if (dynamicobj != null)
                { 
                    var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                    json= javaScriptSerializer.Serialize(((ExpandoObject)dynamicobj).ToDictionary(item => item.Key, item => item.Value));
                    Command.Parameters.Add(new SqlParameter("@json", json));
                }
                

                if (criteria != null)
                { 
                    foreach (KeyValuePair<string, object> pair in criteria)
                    { Command.Parameters.Add(new SqlParameter("@" + pair.Key, pair.Value)); }
                }
                string responsestring = "";
                if (database == "localhost")
                    responsestring = new DatabaseConnection(DatabaseDetail.localhost).ExeNonQuery(Command, CommandType.StoredProcedure);
                else
                    responsestring = new DatabaseConnection(DatabaseDetail.YuvatripDB).ExeNonQuery(Command, CommandType.StoredProcedure);
                if (!String.IsNullOrEmpty(responsestring) && !String.IsNullOrWhiteSpace(responsestring))
                {
                    response = JsonConvert.DeserializeObject<ExpandoObject>(responsestring);
                    data.response = response;
                    status.errorcode = 0;
                    status.errormessage = "No error.";
                }
                else
                {
                    data.response = "blank";
                    status.errorcode = 1;
                    status.errormessage = "No Data Found.";
                }
            }
            catch (Exception exception)
                {
                status.errorcode = 100;
                status.errormessage = exception.Message;
            }
            finally
            {
                data.status = status;
            }
            return data;
        }
        public static dynamic OnlineTransactionCharges(decimal amount, string onlinemode, string paymentmode, bool reverse)
        {
            dynamic data = new ExpandoObject();
            dynamic status = new ExpandoObject();
            dynamic response = new ExpandoObject();

            try
            {
                decimal processingfee = 0;
                decimal processingfeepercentage = decimal.Parse("3.80");
                decimal amountbefore = Math.Ceiling(amount);
                if (!reverse) { amount = amountbefore; }
                

                if (onlinemode == "CreditCard")
                {
                    processingfeepercentage = decimal.Parse("2.00");
                    if (reverse) {  amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;
                }
                if (onlinemode == "AmexCard")
                {
                    processingfeepercentage = decimal.Parse("3.00");
                    if (reverse) { amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;

                }
                if (onlinemode == "ZEROCNF")
                {
                    processingfeepercentage = decimal.Parse("0.00");
                    if (reverse) { amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;

                }
                if (onlinemode == "DebitCard")
                {
                    processingfeepercentage = decimal.Parse("1.00");
                    if (reverse) { amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;
                }
                if (onlinemode == "NetBanking")
                {
                    processingfeepercentage = decimal.Parse("2.00");
                    if (reverse) { amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;
                }
                if (onlinemode == "AirtelMoney")
                {
                    processingfeepercentage = decimal.Parse("2.75");
                    if (reverse) { amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;
                }
                if (onlinemode == "ITZCash")
                {
                    processingfeepercentage = decimal.Parse("3.80");
                    if (reverse) { amountbefore = amount - Math.Ceiling((amount * processingfeepercentage / 100)); }
                    amount = Math.Ceiling((amountbefore * 100) / (100 - processingfeepercentage));
                    processingfee = amount - amountbefore;
                }

                response.amount = amountbefore;
                response.processingfeepercentage = processingfeepercentage;
                response.payuamount = amount;
                response.processingfee = processingfee;

                data.response = response;

                status.errorcode = 0;
                status.errormessage = "No error.";
            }
            catch (Exception exception)
            {
                status.errorcode = 100;
                status.errormessage = exception.Message;
            }
            finally
            {
                data.status = status;
            }
            return data;
        }
        public static string Flatten(ExpandoObject expando)
        {
            StringBuilder sb = new StringBuilder();
            List<string> contents = new List<string>();
            var d = expando as IDictionary<string, object>;
            sb.Append("{ ");
            int i = 0;
            foreach (KeyValuePair<string, object> kvp in d)
            {
                if (kvp.Value is ExpandoObject)
                {
                    ExpandoObject expandoValue = (ExpandoObject)kvp.Value;
                    StringBuilder expandoBuilder = new StringBuilder();
                    
                    expandoBuilder.Append(String.Format("\"{0}\":", kvp.Key));
                    
                    String flat = Flatten(expandoValue);
                    expandoBuilder.Append(flat);

                    string expandoResult = expandoBuilder.ToString();
                    // expandoResult = expandoResult.Remove(expandoResult.Length - 1);
                    expandoResult += "";
                    contents.Add(expandoResult);
                }
                else if (kvp.Value is List<Object>)
                {
                    List<Object> valueList = (List<Object>)kvp.Value;

                    StringBuilder listBuilder = new StringBuilder();
                    
                        listBuilder.Append(String.Format("\"{0}\":[", kvp.Key));
       
                    foreach (Object item in valueList)
                    {
                        if (item is ExpandoObject)
                        {
                            String flat = Flatten(item as ExpandoObject);
                            listBuilder.Append(flat + ",");
                        }
                        //if(item is List<Object>)
                        //{
                        //    List<Object> vlist = (List<Object>)item;
                        //    StringBuilder lbuilder = new StringBuilder();
                        //    if (i == 0)
                        //        lbuilder.Append(String.Format("\"{0}\":[", kvp.Key + "00"));
                        //    i += 1;
                        //    foreach (Object ij in vlist)
                        //    {
                        //        if (ij is ExpandoObject)
                        //        {
                        //            String flat = Flatten(ij as ExpandoObject);
                        //            lbuilder.Append(flat + ",");
                        //        }

                        //    }
                        //    string lresult = lbuilder.ToString();
                        //    lresult = lresult.Remove(lresult.Length - 1);
                        //    lresult += "]";
                        //    contents.Add(lresult);
                        //}
                    }

                    string listResult = listBuilder.ToString();
                    listResult = listResult.Remove(listResult.Length - 1);
                    listResult += "]";
                    contents.Add(listResult);

                }
                else
                {
                    var javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();

                    var obj = kvp.Value;
                    if (obj is DateTime)
                    {
                        DateTime T = (DateTime)obj;
                        obj = T.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                        
                    contents.Add(String.Format("\"{0}\": {1}", kvp.Key,
                    javaScriptSerializer.Serialize(obj)));
                }
                //contents.Add("type: " + valueType);
            }
            sb.Append(String.Join(",", contents.ToArray()));

            sb.Append("}");

            return sb.ToString();
        }
        public static string TitleCase(string value)
        {
            if (!String.IsNullOrEmpty(value) && !String.IsNullOrWhiteSpace(value))
            {
                return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(value.Trim().ToLower());
            }
            else
            {
                return String.Empty;
            }
        }

	 public static string Generatehash512(string text)
        {
            byte[] message = Encoding.UTF8.GetBytes(text);
            UnicodeEncoding UE = new UnicodeEncoding();
            byte[] hashValue;
            SHA512Managed hashString = new SHA512Managed();
            string hex = "";
            hashValue = hashString.ComputeHash(message);
            foreach (byte x in hashValue)
            {
                hex += String.Format("{0:x2}", x);
            }
            return hex;
        }

        public static string GenerateOTP()
        {
            string strPwdchar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string OTP = "";
            Random rnd = new Random();
            for (int i = 1; i <= 6; i++)
            {
                int iRandom = rnd.Next(0, strPwdchar.Length - 1);
                OTP += strPwdchar.Substring(iRandom, 1);
            }
            return OTP;
        }

        
    }
   
}

LittleDemon - FACEBOOK
[ KELUAR ]