Wednesday 28 December 2016

Html and css drop down menu list

Html:
============================
 <div class="ddropdown">
    <button class="ddropbtn">Dropdown</button>
       <div class="ddropdown-content">  
          <a href="javascript:void(0)">level1</a>
          <a href="javascript:void(0)">level2</a>
          <a href="javascript:void(0)">level3</a>
          <a href="javascript:void(0)">level4</a>
      </div>          
</div>
============================

Css:

===========================
<style>
.ddropbtn {
    background-color: #505050;
    color: white;  
    font-size: 15px;
    border: none;
    cursor: pointer;  
    display: inline-block;
    padding: 0px 24.3px;
    border-radius: 0 0 3px 3px;
}
.ddropdown {
    position: relative;
    display: inline-block;
}
.ddropdown-content {
    display: none;
    top: 26px;
    position: absolute;
    background-color: #babfd3;  
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index:999;  
}
.ddropdown-content a {
    color: white;
    text-align: right;
    padding-bottom: 2px;
    text-decoration: none;
    display: block;
    background-color: #babfd3;
    border-bottom: 1px solid #eaeaf1;
}
.ddropdown-content a:hover {background-color: #3a3f9a}
.ddropdown:hover .ddropdown-content {
    display: block;
}
.ddropdown:hover .ddropbtn {
    background-color: #3a3f9a;
}
</style
=======================

upload excel file without saving any where in system in mvc, asp ,vb.net

Using ClosedXML and Excel.4.5 dll.

//Install-Package ClosedXML -Version 0.76.0
//https://www.nuget.org/packages/ClosedXML/0.76.0

//Install-Package ExcelDataReader -Version 2.1.2.3
//https://www.nuget.org/packages/ExcelDataReader/2.1.2.3

Html:
============
 <tr>
                                        <td style="width: 112px;">@common.GetTranslations("File Name", LID)</td>
                                        <td>@Html.TextBox("Dfilename", "", new { type = "file", Class = "Dtext tht fs fel" })</td>
                                        <td><input type="submit" value="@common.GetTranslations("Upload file", LID)" id="btnuploadexcel" class="formBtn" onclick="Loader();" style="min-width: 130px !important;  padding: 3px 0px !important; background-color:cadetblue;   font-size: 15px !important;" /></td>
                                    </tr>

C# code
===============

using ClosedXML.Excel;
using Excel;
   public ActionResult Diamondfile(HttpPostedFileBase Dfilename)
        {
if (Dfilename != null && Dfilename.ContentLength > 0)
            {
                string Extension = Path.GetExtension(Dfilename.FileName);

                if (!(Extension == "csv"))
                {
                    #region Excel File
                    var attachedFile = Dfilename;
                    IExcelDataReader excelReader;
                    if (Extension.ToLower() == ".xls")
                        excelReader = ExcelReaderFactory.CreateBinaryReader(attachedFile.InputStream);
                    else
                        excelReader = ExcelReaderFactory.CreateOpenXmlReader(attachedFile.InputStream);
                   //In asp.net or vb.net 
                   // excelReader = ExcelReaderFactory.CreateBinaryReader(attachedFile.FileContent)
                    //Else
                   // excelReader = ExcelReaderFactory.CreateOpenXmlReader(attachedFile.FileContent)                  



  excelReader.IsFirstRowAsColumnNames = true;
                    DataSet result = excelReader.AsDataSet();
                    System.Data.DataTable dtResult = result.Tables[0];
                    uploadexcelfile(dtResult);


                    #endregion
                }            
                else
                {
                  //code here csv file
                }
            }
            else
            {
                TempData["Fileupload"] = "no";
            }
            
            return View();
}
=================================


    public void uploadexcelfile(System.Data.DataTable dtResult)
        {
            if (dtResult.Rows.Count > 0)
            {
                string inputDataRead;
                string StockNumbers = string.Empty;
                string Stockexist = string.Empty;

                foreach (DataRow eachValue in dtResult.Rows)
                {           
                    //code here
                }
            }
            else
            {
                TempData["Fileupload"] = "no";
               
            }
            
        }
==============================



Monday 19 December 2016

PayPal without dll using only email

Web config
==============
    <!-- Start Paypal pages-->
    <add key="PayPalUrl" value="https://www.sandbox.paypal.com/cgi-bin/webscr" />
    <add key="PaypalEmailId" value="saurabh_kashyap-facilitator@seologistics.com"></add>
    <add key="PaypalSuccessUrl" value="/Paypal/PayoutSuccess"></add>
    <add key="PaypalErrorUrl" value="/Paypal/PayoutError"></add>
    <add key="PaypalNotifyUrl" value="/Paypal/PayoutNotify"></add>
    <add key="EnvironmentType" value="Dev"></add>
   
    <!-- End Paypal Pages-->
Controler
==================

namespace EMPBenefits.Controllers
{
    public class PayPalController : Controller
    {
        #region Payout amount to EMP by admin...

        #region Declare all object
        /// <summary>
        /// Declare object of outside class
        /// </summary>
        GenericUnitOfWork _Unitofwork = new GenericUnitOfWork();
        EncryptDecrypt objEncDec = new EncryptDecrypt();
        Sendmail objsendmail = new Sendmail();
        #endregion
        public ActionResult PaymentWithPaypal(_Employerreg objpaymentdetails)
        {
            TempData["userpaymentinfo"] = objpaymentdetails;
            return PayoutEMP(objpaymentdetails);
        }

        public ActionResult PayoutEMP(_Employerreg objdata)
        {
           
           // _Employerreg objdata = (_Employerreg)Session["Paymentdetails"];
            int EMPId = Convert.ToInt32(objdata.employeerid);
            decimal EMPEarning = Convert.ToDecimal(objdata.TotalPrice);
            string Employeername = Convert.ToString(objdata.firstName);
            string EMPPaypalEmail = ConfigurationManager.AppSettings["PaypalEmailId"];
            string redirect = ConfigurationManager.AppSettings["PayPalUrl"] + "?cmd=_xclick&business=" + EMPPaypalEmail;
            redirect += "&item_name=" + Employeername;
            redirect += "&quantity=" + 1;
            string totalPaymentAmount = Convert.ToString(EMPEarning);
            redirect += "&amount=" + totalPaymentAmount;
            redirect += "&ItemTotal=" + totalPaymentAmount;
            redirect += "&tax_cart=" + "1";
            redirect += "&rm=" + "2";
            redirect += "&currency_code=USD";
            redirect += "&custom=" + EMPPaypalEmail + "|" + EMPId + "|" + totalPaymentAmount;
            redirect += "&notify_url=" + ConfigurationManager.AppSettings["PageURL"] + ConfigurationManager.AppSettings["PaypalNotifyUrl"];
            redirect += "&return=" + ConfigurationManager.AppSettings["PageURL"] + ConfigurationManager.AppSettings["PaypalSuccessUrl"];
            redirect += "&cancel_return=" + ConfigurationManager.AppSettings["PageURL"] + ConfigurationManager.AppSettings["PaypalErrorUrl"];

            TempData["requesturl"] = redirect;
            return Redirect(redirect);
        }

        public ActionResult PayoutSuccess()
        {
            string strSandbox = ConfigurationManager.AppSettings["PayPalUrl"];
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(Request.ContentLength);
            string strRequest = System.Text.Encoding.ASCII.GetString(param);
            string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;          
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
            //enquiry status and update  database
            if (strResponse == "VERIFIED")
            {
                if (TempData["CurrentTransactionId"] == null)
                {
                    if (System.Configuration.ConfigurationManager.AppSettings["EnvironmentType"] == "Dev")
                    {
                        System.Collections.Specialized.NameValueCollection these_argies = System.Web.HttpUtility.ParseQueryString(strResponse_copy);
                        string user_email = these_argies["payer_email"];
                        string pay_stat = these_argies["payment_status"];
                        string txn_id = these_argies["txn_id"];
                        string payer_id = these_argies["payer_id"];
                        string payment_status = these_argies["payment_status"];
                        string payment_type = these_argies["payment_type"];
                        string payment_fee = these_argies["payment_fee"];
                        string receiver_id = these_argies["receiver_id"];
                        string handling_amount = these_argies["handling_amount"];
                        string payment_gross = these_argies["payment_gross"];
                        string custom = these_argies["custom"];

                        int providerId = 0;
                        decimal providerAmount = 0;
                        var customList = custom.Split('|');
                        if (customList.Count() == 3)
                        {
                            providerId = Convert.ToInt32(customList[1]);
                            Decimal.TryParse(customList[2], NumberStyles.Any, CultureInfo.InvariantCulture, out providerAmount);
                        }

                        _Employerreg objuserinfo = (_Employerreg)TempData["userpaymentinfo"];
                        tblPayment trns = new tblPayment();                      
                        trns.status = payment_status;
                        trns.amount =Convert.ToDecimal(payment_gross);
                        trns.transaction_date = DateTime.UtcNow;
                        trns.transactionNumber = txn_id;
                        trns.employerId = objuserinfo.employeerid;
                        trns.paymentOptionId = 1;
                        trns.request = Convert.ToString(TempData["requesturl"]);
                        _Unitofwork.GetRepositoryInstance<tblPayment>().Add(trns);
                        _Unitofwork.SaveChanges();
                        int id=Convert.ToInt32(objuserinfo.employeerid);
                        tblEmployer objemployee = _Unitofwork.GetRepositoryInstance<tblEmployer>().GetFirstOrDefaultByParameter(i => i.employerId == id);
                        objemployee.paymentOptionId = 1;
                        objemployee.lastUpdatedDate = DateTime.Now;
                        objemployee.lastUpdatedByUserId = id;                      
                        objemployee.numberOfEmployees = objuserinfo.numberofemp;
                        objemployee.subscriptionStartDate = DateTime.UtcNow;                      
                        objemployee.userName=  GenerateRandom.RandomUserName(Convert.ToInt32(ConfigurationManager.AppSettings["UserNameLength"]));
                        objemployee.password = objEncDec.Encrypt(GenerateRandom.RandomPassword(Convert.ToInt32(ConfigurationManager.AppSettings["PasswordLength"])));
                        objemployee.isPaid = true;
                        _Unitofwork.GetRepositoryInstance<tblEmployer>().Update(objemployee);
                        _Unitofwork.SaveChanges();                      
                    }
                }
             
            }
            else if (strResponse == "INVALID")
            {            
                PayoutError();              
            }
            return RedirectToAction("success", "Home");
        }

        public ActionResult PayoutError()
        {
            TempData["PaypalResponseAfterPayout"] = "There were some issues dring the payment and it is not completed. Please try again";
            return RedirectToAction("index", "Home");
        }

        public ActionResult PayoutNotify()
        {
            string strSandbox = ConfigurationManager.AppSettings["PayPalUrl"];
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(Request.ContentLength);
            string strRequest = System.Text.Encoding.ASCII.GetString(param);
            string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;
            //Send the request to PayPal and get the response
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
            if (System.Configuration.ConfigurationManager.AppSettings["EnvironmentType"] == "Live")
            {
                System.Collections.Specialized.NameValueCollection these_argies = System.Web.HttpUtility.ParseQueryString(strResponse_copy);
                string user_email = these_argies["payer_email"];
                string pay_stat = these_argies["payment_status"];
                string txn_id = these_argies["txn_id"];
                string payer_id = these_argies["payer_id"];
                string payment_status = these_argies["payment_status"];
                string payment_type = these_argies["payment_type"];
                string payment_fee = these_argies["payment_fee"];
                string receiver_id = these_argies["receiver_id"];
                string handling_amount = these_argies["handling_amount"];
                string payment_gross = these_argies["payment_gross"];
                string custom = these_argies["custom"];

                int providerId = 0;
                decimal providerAmount = 0;
                var customList = custom.Split('|');
                if (customList.Count() == 3)
                {
                    providerId = Convert.ToInt32(customList[1]);
                    Decimal.TryParse(customList[2], NumberStyles.Any, CultureInfo.InvariantCulture, out providerAmount);
                }
                //Tbl_Transactions trns = new Tbl_Transactions();
                //trns.AppointmentId = 0;
                //trns.AdminPromo = 0;
                //trns.AmountPaid = providerAmount; // Payout Amount
                //trns.BookingFee = 0;
                //trns.PayerMemberId = Session["AdminMember"] != null ? Convert.ToInt32(Session["AdminMember"]) : 0; // Admin Id
                //trns.ProviderAmount = -providerAmount;
                //trns.ProviderFee = 0;
                //trns.ProviderPromo = 0;
                //trns.RecieverMemberId = providerId;  //Provider Id
                //trns.TransactionStatusId = 1;
                //trns.VatPercent = 0;
                //trns.OfferDiscount = _GlobalDiscount;
                //trns.SeekerAmount = 0;
                //trns.TransactionTypeId = 3;  // Admin pays to provider: monthly earning is paid by admin to provider
                //trns.CreatedOn = DateTime.UtcNow;
                //trns.ModifiedOn = DateTime.UtcNow;
                //trns.PayerPayPalId = payer_id;
                //trns.PaypalToken = txn_id;
                //trns.PaypalPaymentId = txn_id;
                //trns.ModifiedOn = DateTime.UtcNow;
                //trns.TransactionStatusId = 2;
                //_unitOfWork.GetRepositoryInstance<Tbl_Transactions>().Add(trns);
                //_unitOfWork.SaveChanges();
            }
            return null;
        }
        #endregion

    }
}