Saturday, 7 January 2017

Json String to Key Value Pair in C#, Xamarin Android


Json String to Key Value Pair in C#, Xamarin Android

public static Dictionary<string, string> ParseJSONString(string s)
        {
            Regex reg = new Regex("\"(?<Key>[\\w]*)\":\"?(?<Value>([\\s\\w\\d\\.\\\\\\-/:_\\+]+(,[,\\s\\w\\d\\.\\\\\\-/:_\\+]*)?)*)\"?");
            MatchCollection matchCollection  = reg.Matches(s);

            Dictionary<string, string> json = new Dictionary<string, string>();

            foreach (Match kv in matchCollection)
            {
                json.Add(kv.Groups["Key"].Value, kv.Groups["Value"].Value);

            }
            return json;
        }

Spinner-Progress-Bar-Xamarin-Android-C#

Spinner-Progress-Bar-Xamarin-Android-C#


 
var progressDialog = ProgressDialog.Show(this, "Please wait...", "Checking info...", true);
    new Thread(new ThreadStart(delegate
    {
    //Your Code
    RunOnUiThread(() => Toast.MakeText(this, "Toast within progress dialog.", ToastLength.Long).Show());
//Hide Progress Dialog after completion of Task
            RunOnUiThread(() => progressDialog.Hide());
  })).Start();

Change-Status-bar-Color-xamarin-android-C#

Change Status bar Color in Xamarin Android C#.
It is supported for Android 5 or greater.

Window.AddFlags(Android.Views.WindowManagerFlags.DrawsSystemBarBackgrounds);
Window.SetStatusBarColor(Color.ParseColor("#004D40"));

Sunday, 26 June 2016

PayU india ASP.Net MVC Integration

Before implementing you need to get MERCHANT_KEYSALT  From PayU
Replace Red color variables with correct values.
BillingDetails  is Entity with only required parameters:


 public class BillingDetails
    {
        public int Id { get; set; }
        [Display(Name = "Billing Amount (₹)")]
        public double Amount { get; set; }
        public UserType UserType { get; set; }
        public int UserId { get; set; }
        [Display(Name = "Customer Name")]
        public string FirstName { get; set; }
        [Display(Name = "Customer Email")]
        public string EmailId { get; set; }
        public string Phone { get; set; }
        [Display(Name = "Product Info")]
        public string ProductInfo { get; set; }
        public string Status { get; set; }
        public string ReturnUrl { get; set; }
        public DateTime CreatedOn { get; set; }
        public int CreatedBy { get; set; }

    }


________________________________________________________________________________



using System;
using System.Net;
using System.Security.Cryptography;



[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult MakePayment(BillingDetails bd)
        {
       
            RemotePost myremotepost = new RemotePost();
            string key = "MERCHANT_KEY";
            string salt = "SALT";
            myremotepost.Url =  "https://secure.payu.in/_payment";
            myremotepost.Add("key", key);
            string txnid = Generatetxnid();
            myremotepost.Add("txnid", txnid);
            myremotepost.Add("amount", bd.Amount.ToString());
            myremotepost.Add("productinfo", bd.ProductInfo);
            myremotepost.Add("firstname", bd.FirstName);
            myremotepost.Add("phone", bd.Phone);
            myremotepost.Add("email", bd.EmailId);
            myremotepost.Add("surl","SuccessUrl");
            myremotepost.Add("furl", "FailuarURL");
            myremotepost.Add("service_provider", "payu_paisa");
            myremotepost.Add("udf1", bd.Id.ToString());
            string hashString = key + "|" + txnid + "|" + bd.Amount + "|" + bd.ProductInfo + "|" +               bd.FirstName + "|" + bd.EmailId + "|" + bd.Id + "||||||||||" + salt;
            string hash = Generatehash512(hashString);
            myremotepost.Add("hash", hash);

            myremotepost.Post();

            return View();
        }




public class RemotePost
        {
            private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();


            public string Url = "";
            public string Method = "post";
            public string FormName = "form1";

            public void Add(string name, string value)
            {
                Inputs.Add(name, value);
            }

            public void Post()
            {
                System.Web.HttpContext.Current.Response.Clear();

                System.Web.HttpContext.Current.Response.Write("<html><head>");

                System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName));
                System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url));
                for (int i = 0; i < Inputs.Keys.Count; i++)
                {
                    System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]]));
                }
                System.Web.HttpContext.Current.Response.Write("</form>");
                System.Web.HttpContext.Current.Response.Write("</body></html>");

                System.Web.HttpContext.Current.Response.End();
            }
        }


        public 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 string Generatetxnid()
        {

            Random rnd = new Random();
            string strHash = Generatehash512(rnd.ToString() + DateTime.Now);
            string txnid1 = strHash.ToString().Substring(0, 20);

            return txnid1;
        }

========================================================================
If you are looking for more help write me on kalubarmea@gmail.com