Tuesday, 29 July 2014

How to Post JSON Data to an MVC5 Controller via Ajax

It's just a simple form where you enter your first name and last name, and then use a multiselect dropdown to pick your favorite bands.

Home













and enter your First name, Last name and select your favorite Car.














Step 1: First Create PersonController.css

 [HttpGet]
        public ActionResult Index()
        {
            return View(new PersonModel());
        }

        [HttpPost]
        public JsonResult BadSave(string first, string last, List<string> favoriteBands)
        {
            Console.WriteLine(first);
            Console.WriteLine(last);
            Console.WriteLine(String.Join(" ",favoriteBands));

            return Json(new { result = "saved the bad way" });
        }

        [HttpPost]
        public JsonResult GoodSave(PersonModel model)
        {
            Console.WriteLine(model.First);
            Console.WriteLine(model.Last);
            Console.WriteLine(String.Join(" ", model.FavoriteBands));

            return Json(new { result = "saved the good way" });

        }


Step 2 : Create PersonModel.css Model

public class PersonModel
    {
        [DisplayName("First Name")]
        public string First { get; set; }

        [DisplayName("Last Name ")]
        public string Last { get; set; }

        [DisplayName("Favorite Car")]
        public List<string> FavoriteBands { get; set; }
    }

Step 3 : Create the View ie Index.cshtml

@model MVCJsonPost.Models.PersonModel
@{
    ViewBag.Title = "Home";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Home</h2>

<div>
    @Html.LabelFor(m => m.First)
    @Html.EditorFor(m => m.First)
</div>

<div>
    @Html.LabelFor(m => m.Last)
    @Html.EditorFor(m => m.Last)
</div>

<div>
    @Html.LabelFor(m => m.FavoriteBands)
    @Html.DropDownListFor(m => m.FavoriteBands, new SelectList(
                  new List<Object>{ 
                       new { value = 0 , text = "Honda City"  },
                       new { value = 1 , text = "Renault fluence" },
                       new { value = 2 , text = "Hyundai xcent"}
                    },
                  "value",
                  "text",
                   Model.FavoriteBands),
                    new { multiple = "multiple" })


</div>

<div>
    <input type="button" value="Bad Submit" id="bad" />
    <input type="button" value="Good Submit" id="good" />
</div>

<label id="result"></label>

Step 4: Create the js file i.e person.js in Script Folder

$(document).ready(function () {
    $('#good').click(function () {
        var request = new PersonModel();
        debugger;
        $.ajax({
            url: "Person/GoodSave",
            dataType: 'json',
            contentType: "application/json",
            type: "POST",
            data: JSON.stringify(request), //Ahhh, much better
            success: function (response) {
                $("#result").text(response.result);
            }
        });
    });

    $('#bad').click(function () {
        var request = new PersonModel();
        debugger;
        $.ajax({
            url: "Person/BadSave",
            dataType: 'json',
            type: "POST",
            data: "first=" + request.First + "&last=" + request.Last + "&favoriteBands=" + request.FavoriteBands, //How do you encode an array?? This doesn't even work right
            success: function (response) {
                $("#result").text(response.result);
            }
        });
    });
});

function PersonModel() {
    var self = this;
    self.First = $("#First").val();
    self.Last = $("#Last").val();

    self.FavoriteBands = $.map($('#FavoriteBands option:selected'),
                      function (e) { return $(e).val(); });
}


Run The Application  and fill the form and place some breakpoint to test and debug line by line















Done :)




Friday, 25 July 2014

How to Creating or Deleting a Profile in Another Language in LinkedIn

You can Create your profile in any number of language(to create you should visit http://www.linkedin.com/profile/edit-profile-in-another-language )  from the View Profile page.
While you can't change the language of your primary profile, you can create as many other language profiles as there are languages available.
So Now Question is How to create your profile in another language:
So For that :
  1. Click Profile at the top of your homepage.
  2. Click the  down arrow next to the Edit Profile button and select "Create profile in another language".
  3. Choose a language from the dropdown list and update your first name and last name if they're different in the new profile's language.
  4. Translate your existing Professional Headline.
    • Translations aren't done for you. You'll need to translate your own personal content.
  5. Click Create Profile to go to the Edit Profile page of your new language profile.
  6. Click any  Edit icon and translate the open fields.
  7. Click Save and continue editing other sections.
And How to delete a secondary language profile:
  1. Move your cursor over Profile at the top of your homepage and select Edit Profile.
  2. Select the language from the Profile dropdown list in the upper right.
  3. Click the Delete this profile link. If this link doesn't appear, the profile you're viewing is your primary profile. You can't change your primary profile's language setting.
  4. Click Delete.
Notes:
  • It is not possible to make another language profile as your default profile.

Thursday, 24 July 2014

How to Back Up Your Gmail Account

On February 28, 2011, Google confirmed that many Gmail users had temporarily lost access to their emails.If you're worried about ever losing your emails to a similar glitch, it's probably a good idea to regularly backup your Gmail account. By configuring an email client on your computer, you can download your emails onto your hard drive by following these steps
Method 1: Mail Settings in Gmail
Step 1: Log into Gmail and click on "Mail Settings" in the top right hand corner. This can be accessed from any Gmail page.
Step 2: Locate and click on the "Forwarding and POP/IMAP" tab.
Step 3: Look under "POP Download". Select the first option, "Enable POP for all mail (even mail that's already been downloaded)".
Step 4: Click on "Save Changes" at the bottom.
Step 5: Configure your mail client following the steps below. Once your mail client is configured to download your email, remember to open it periodically to backup.
Method 2 : Download Gmail Backup
Step 1: Go to: https://code.google.com/p/gmail-backup-com/ and select "download" to install the software.
Step 2: Open your command or terminal and go to directory of the program.
Step 3: Run the program and replace "dir" with the directory name you want to use and your email address with your own password.

Tuesday, 22 July 2014

Ccavenue Payment Integration in asp.net mvc5



Here i am writing a simple article to integrate Ccavenue payment integration.

Controller 

public ActionResult ccavenueForm()
 {
   try
            {
                Payment_ccavenue myUtility = new Payment_ccavenue();
             //This id(also User Id)  available at "Generate Working Key" of "Settings & Options" ;
                string Merchant_Id = "M_ravicm_14844";
             // 'your script should substitute the amount here in the quotes provided here
                string Amount = Session["Payment_Amount_CCAvenue"].ToString();
                string Order_Id = Session["Custom_Field"].ToString();// 'your script should substitute the order description here in the quotes provided here
                string Redirect_Url = GlobalVariables.Redirect_Redirect_ccavenue;//'your redirect URL where your customer will be redirected after authorisation from CCAvenue               
                string WorkingKey = "1r5aced2v9mmaqhb3k";// 'put in the 32 bit alphanumeric key in the quotes provided here.Please note that get this key ,login to your CCAvenue merchant account and visit the "Generate Working Key" section at the "Settings & Options" page. 
                ViewBag.Redirect_Redirect_ccavenue = Redirect_Url;
                ViewBag.Checksum = myUtility.getchecksum(Merchant_Id, Order_Id, Amount, Redirect_Url, WorkingKey);
                return View();
            }
            catch
            {
                // string S = Exception.ToString();
                return RedirectToRoute("ErrorHandling");
            }
        }

View 


<!-- #include virtual = "/payment/libfuncs.asp" -->
<HTML>
<HEAD>
<TITLE>Sub-merchant checkout page: www.mywebsite.com</TITLE>
</HEAD>
<BODY onload="document.forms['ccavenueForm'].submit();">
@{
string     Merchant_Id = "M_ravicm_14844"; //This id(also User Id)  available at "Generate Working Key" of "Settings & Options" ;
string Amount = Session["Payment_Amount_CCAvenue"].ToString();// 'your script should substitute the amount here in the quotes provided here
string Order_Id = Session["Custom_Field"].ToString();// 'your script should substitute the order description here in the quotes provided here
string Redirect_Url = @ViewBag.Redirect_Redirect_ccavenue;//'your redirect URL where your customer will be redirected after authorisation from CCAvenue
  //  Amount = "21";
    string WorkingKey = "2er4ed2v9mmaqhb3k"  ;// 'put in the 32 bit alphanumeric key in the quotes provided here.Please note that get this key ,login to your CCAvenue merchant account and visit the "Generate Working Key" section at the "Settings & Options" page. 
    
    string Checksum = ViewBag.Checksum;
    //Amount = "1111";
    string  billing_cust_name = "";
    string  billing_cust_address = "";
    string  billing_cust_state = "";
    string  billing_cust_country = "";
    string  billing_cust_tel = "";
    string  billing_cust_email = "";
    string delivery_cust_name = "";
    string  delivery_cust_address = "";
    string  delivery_cust_state = "";
    string  delivery_cust_country = "";
    string  delivery_cust_tel = "";
    string  delivery_cust_notes = "";
    string  Merchant_Param = "" ;
    string  billing_zip = "";
    string  delivery_zip = "";
    string billing_city = "";
    string delivery_city = "";

    }
<formmethod="post"name="ccavenueForm"action="https://www.ccavenue.com/shopzone/cc_details.jsp">
    <input type=hidden name=Merchant_Id value="@Merchant_Id">
    <input type=hidden name=Amount value="@Amount">
    <input type=hidden name=Order_Id value="@Order_Id">
    <input type=hidden name=Redirect_Url value="@Redirect_Url">
    <input type=hidden name=Checksum value="@Checksum">
    <input type="hidden" name="billing_cust_name" value="@billing_cust_name"> 
    <input type="hidden" name="billing_cust_address" value="@billing_cust_address"> 
    <input type="hidden" name="billing_cust_state" value="@billing_cust_state">
    <input type="hidden" name="billing_cust_country" value="@billing_cust_country"> 
    <input type="hidden" name="billing_cust_city" value="@billing_city"> 
    <input type="hidden" name="billing_zip_code" value="@billing_zip"> 
    <input type="hidden" name="billing_cust_tel" value="@billing_cust_tel"> 
    <input type="hidden" name="billing_cust_email" value="@billing_cust_email"> 
    <input type="hidden" name="delivery_cust_name" value="@delivery_cust_name"> 
    <input type="hidden" name="delivery_cust_address" value="@delivery_cust_address">
    <input type="hidden" name="delivery_cust_country" value="@delivery_cust_country"> 
    <input type="hidden" name="delivery_cust_state" value="@delivery_cust_state">
    <input type="hidden" name="delivery_cust_tel" value="@delivery_cust_tel"> 
    <input type="hidden" name="delivery_cust_notes" value="@delivery_cust_notes"> 
    <input type="hidden" name="Merchant_Param" value="@Merchant_Param"> 
    <input type="hidden" name="billing_zip_code" value="@billing_zip"> 
    <input type="hidden" name="delivery_cust_city" value="@delivery_city"> 
    <input type="hidden" name="delivery_zip_code" value="@delivery_zip"> 
    <!--<INPUT TYPE="submit" value="submit">-->
    </form>
</BODY>
</HTML>

Monday, 21 July 2014

How to Integrate Payzippy Payment gateway in Asp.net3.5 ?


Payzippy is one of the latest and Fast growing  payment gateway providing service in India(fom flipkart.com). They are providing SDK for PHP and Java but still no SDK for .NET platform. But Using Payzippy Rest API (support for JSON) , We can create Payment Integration in ASP.NET .

CS File

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Security.Cryptography;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
       protected Default2()
        {
            this.Init += Charging_Init;
            Main();
        }
       private void Charging_Init(object sender, EventArgs e)
        {
            this.EnableViewState = false;
        }
       private static string secretKey = "KEY_KEY_KEY_KEY_KEY";
        private static string generateSHA256(String input)
        {
            SHA256Managed crypt = new SHA256Managed();
            string hash = String.Empty;
            byte[] crypto = crypt.ComputeHash(Encoding.ASCII.GetBytes(input), 0, Encoding.ASCII.GetByteCount(input));
            foreach (byte bit in crypto)
            {
                hash += bit.ToString("x2");
            }
            return hash;
        }
        static string GenHash(Dictionary<string, string> chargingParams)
        {
            // Acquire keys and sort them.
            List<string> list = new List<string>(chargingParams.Keys);
            list.Sort();
            StringBuilder stringForHash = new StringBuilder();
            // Loop through keys.
            foreach (var key in list)
            {
                stringForHash.Append(chargingParams[key] + '|');
            }
            stringForHash.Append(secretKey);
            return generateSHA256(stringForHash.ToString());
        }
        public Dictionary<string, string> chargingParams;
        private void Main()
        {
            var currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            this.chargingParams = new Dictionary<string, string>();
            chargingParams.Add("merchant_id", "test"); //Your MID issued by PayZippy.
            chargingParams.Add("buyer_email_address", "email@gmail.com"); // Email Address
            chargingParams.Add("merchant_transaction_id", "PAY_" + currentTime); //Your Transaction Id
            chargingParams.Add("transaction_type", "SALE"); //This is the default Value.
            chargingParams.Add("transaction_amount", "10000"); //Amount must be in paise. So, 1 Rupee= 100.
            chargingParams.Add("payment_method", "CREDIT"); // CREDIT,DEBIT,EMI,NET
            chargingParams.Add("bank_name", ""); //Bank Name required in case of EMI/NET.
            chargingParams.Add("emi_months", "0"); // Emi Months in case of EMI.
            chargingParams.Add("currency", "INR"); //INR is default.
            chargingParams.Add("ui_mode", "IFRAME"); //REDIRECT/IFRAME.
            chargingParams.Add("hash_method", "SHA256"); //MD5, SHA256
            chargingParams.Add("merchant_key_id", "payment"); //This is the default value.
            chargingParams.Add("timegmt", currentTime.ToString());
            chargingParams.Add("callback_url", "http://busnow.in/bus/default.aspx");
            chargingParams.Add("hash", GenHash(chargingParams));

            StringBuilder builder = new StringBuilder();
            builder.Append("https://www.payzippy.com/payment/api/charging/v1?");
            foreach (var entry in chargingParams)
            {
                builder.AppendFormat("{0}={1}&", entry.Key, entry.Value);
            }
            Console.WriteLine(builder.ToString());


        }

VIEW FILE(Code Design File)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" action="https://www.payzippy.com/payment/api/charging/v1" method="post" runat="server">
        <div>
            <div>
                <%
                var url = "https://www.payzippy.com/payment/api/charging/v1?";
                foreach (var entry in chargingParams)
                {
                %>
                <input type="hidden" name="<%=entry.Key %>" value="<%=entry.Value %>" />
                <%
                url += entry.Key + "=" + entry.Value + "&";
                // do something with entry.Value or entry.Key
                }

                %>

                <input type="submit" />
            </div>
            <iframe width="500" height="500" src="<%=url %>"></iframe>
        </div>
    </form>
    <script>
        var x = document.getElementById("__VIEWSTATE");
        x.parentNode.removeChild(x);
    </script>
</body>

</html>

When you will Run you will get error message.


So first you have to register with PayZippy and get 

1. MID (merchant_id)
2. Secure key (used to determine hash)

3. Secure key id (merchant_key_id)


Then  place the value in the code and test :)

Wednesday, 16 July 2014

Enable PayPal IPN (Instant Payment Notifications)

Enable PayPal IPN (Instant Payment Notifications)

PayPal has many mechanism for making your site’s checkout experience more secure and a better experience for your users. Instant Payment Notifications helps by increasing both the security and usability of your checkout experience. IPN works by sending messages directly between PayPal and your site. Using this channel of communication, your site can automatically update when orders complete. Without IPN, orders can get lost due to user error. By enabling IPN, you give PayPal the ability to directly communicate with your site, making the checkout process easy and secure.
PayPal IPN is required for some features such as recurring payments.
Below are the instructions on how to enable IPN for your Vantage install:
Note: In order to use IPN, you will need a PayPal business account. Upgrading is easy and free. Just log into your PayPal account and click Upgrade.
  1. Log into your PayPal account
  2. Click My Account > Profile
  3. Click Selling Tools
  4. Under Selling Preferences, look for Instant Payment Notification Preferences
  5. Click Choose IPN Settings
  6. In another tab, open up your Vantage install and go to the PayPal Gateway Settings under the Payments > Setting page.
  7. Copy and Paste the Listener URL from the PayPal Gateway Settings into the Notification URL field on the Instant Payment Notification Preferences page on PayPal.com
  8. Press Save on PayPal.com
  9. Go back to your PayPal Gateway Settings, and check the Enable IPN box.
  10. Press Save. PayPal IPN is now enabled.
Notes for Return URL:
  • If any of your payment plans use recurring payments, this option must be checked. PayPal will be unable to communicate with your site otherwise.
  • If you have no other sites that use PDT, you can enter any URL into Return URL. Vantage controls the return URL and overrides any URL entered into Return URL. Regardless, we recommend entering your site’s root URL (IE: www.yoursite.com)
  • If you have another site that uses PDT, you should enter the return URL that you prefer for that site. Again, Vantage controls the return URL for your Vantage site and does not use the return URL provided on your PayPal account.
  • When PayPal IPN or PDT is enabled, the low-security validation mechanism used to validate non-IPN or non-PDT purchases will be disabled.