Beispiel #1
0
        public ActionResult EditPost(AdManageViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                else
                {
                    long     UrlId       = (long)TempData["AdId"];
                    AdManage objAdManage = adManageRepository.GetAdById(UrlId);
                    objAdManage.UpdateDate  = DateTime.Now.Date;
                    objAdManage.UpdatedBy   = Convert.ToInt32(Session["UserId"]);
                    objAdManage.Title       = model.Title;
                    objAdManage.Description = model.Description;
                    objAdManage.RegistAdId  = Convert.ToInt64(Session["UserId"]);
                    adManageRepository.Edit(objAdManage);
                    return(RedirectToAction("Index", "AdManage"));
                }
            }
            catch (Exception ex)
            {
            }
            return(View());
        }
Beispiel #2
0
 public ActionResult Edit(int Id)
 {
     try
     {
         AdManageViewModel objAdManage = new AdManageViewModel();
         objAdManage      = Mapper.Map <AdManage, AdManageViewModel>(adManageRepository.GetAdById(Id));
         TempData["AdId"] = objAdManage.AdId;
         TempData.Keep();
         objAdManage.Description = System.Web.HttpUtility.HtmlDecode(objAdManage.Description);
         return(View(objAdManage));
     }
     catch (Exception ex)
     {
     }
     return(View());
 }
        public ActionResult Purchase(AdManageViewModel objAdModel)
        {
            PaymentRepository paymentrepo = new PaymentRepository(db);
            var paymentinfo = paymentrepo.GetPaymentByRegistId(Convert.ToInt32(Session["UserId"]));

            objAdModel.Paymentstatus = CommanClass.PaymentStatus.Pending;
            Session["PaymentStatus"] = false;

            if (paymentinfo != null)
            {
                if (paymentinfo.IsSuccess)
                {
                    objAdModel.Paymentstatus = CommanClass.PaymentStatus.Sucess;
                    Session["PaymentStatus"] = true;
                }
                else
                {
                    objAdModel.Paymentstatus = CommanClass.PaymentStatus.Failed;
                }
            }
            else
            {
                Session["IsPaymentPrecessing"] = "Processing";
            }

            if (Convert.ToInt32(Session["SelectedPlans"]) == Convert.ToInt32(Comman.CommanClass.PlanType.Plan1))
            {
                TempData["PlanAmount"] = Convert.ToInt32(Comman.CommanClass.Plans.Plan1);
            }
            else if (Convert.ToInt32(Session["SelectedPlans"]) == Convert.ToInt32(Comman.CommanClass.PlanType.Plan2))
            {
                TempData["PlanAmount"] = Convert.ToInt32(Comman.CommanClass.Plans.Plan2);
            }
            else
            {
                TempData["PlanAmount"] = Convert.ToInt32(Comman.CommanClass.Plans.Plan3);
            }

            TempData.Keep("PlanAmount");

            //Stripe credentials
            var stripePublishKey = ConfigurationManager.AppSettings["PublishableKey"];

            ViewBag.StripePublishKey = stripePublishKey;

            return(View(objAdModel));
        }
        public ActionResult Purchase(string stripeEmail, string stripeToken, AdManageViewModel model)
        {
            AdManage objAdManage = new AdManage();
            var      result      = new JsonResult();

            int    selectedplan = Convert.ToInt32(TempData["PlanAmount"]);
            string planname     = Enum.GetName(typeof(CommanClass.Plans), selectedplan);
            int    planvalue    = (int)Enum.Parse(typeof(CommanClass.PlanType), planname.ToString());
            int    planamount   = selectedplan * 100;
            string FileName     = string.Empty;
            int    userid       = Convert.ToInt32(Session["UserId"]);
            var    customers    = new StripeCustomerService();
            var    charges      = new StripeChargeService();

            try
            {
                var RegisteredUser = registrationRepository.GetClientById(userid);

                if (!string.IsNullOrEmpty(stripeEmail))
                {
                    var customer = customers.Create(new StripeCustomerCreateOptions
                    {
                        Email       = stripeEmail,
                        SourceToken = stripeToken
                    });

                    var charge = charges.Create(new StripeChargeCreateOptions
                    {
                        Amount      = planamount,
                        Description = selectedplan.ToString(),
                        //Currency = "usd",
                        Currency   = "eur",
                        CustomerId = customer.Id
                    });

                    //Save Response in PaymentTransaction Table
                    PaymentTransaction payment = new PaymentTransaction()
                    {
                        RegistId                             = userid,
                        Customer_stripeEmail                 = stripeEmail,
                        Customer_Id                          = customer.Id,
                        Customer_stripeToken                 = stripeToken,
                        Customer_Created                     = customer.Created,
                        Customer_DefaultSourceId             = customer.DefaultSourceId,
                        Customer_InvoicePrefix               = customer.InvoicePrefix,
                        Customer_StripeResponse_RequestId    = customer.StripeResponse.RequestId,
                        Customer_StripeResponse_ResponseJson = customer.StripeResponse.ResponseJson,

                        Charge_Id     = charge.Id,
                        Charge_Amount = charge.Amount,
                        Charge_BalanceTransactionId = charge.BalanceTransactionId,
                        Charge_Created               = charge.Created,
                        Charge_CustomerId            = charge.CustomerId,
                        Charge_Description           = charge.Description,
                        Charge_FailureCode           = charge.FailureCode,
                        Charge_FailureMessage        = charge.FailureMessage,
                        Charge_Outcome_SellerMessage = charge.Outcome.SellerMessage,
                        Charge_Paid      = charge.Paid,
                        Charge_Source_Id = charge.Source.Id,
                        Charge_Status    = charge.Status,
                        Charge_StripeResponse_RequestId    = charge.StripeResponse.RequestId,
                        Charge_StripeResponse_ResponseJson = charge.StripeResponse.ResponseJson,
                        IsSuccess     = true,
                        Response      = "Complete",
                        PaymentMethod = (int)CommanClass.PaymentMethod.Stripe
                    };
                    _paymentRepository.AddPayment(payment);
                    //_paymentRepository.SaveAll();

                    //Insert stripe response information in PaymentTransaction table
                    //db.PaymentTransaction.Add(payment);
                    //db.SaveChanges();

                    RegisteredUser.PaymentStatus = true;
                    registrationRepository.Edit(RegisteredUser);

                    if (!string.IsNullOrEmpty(charge.FailureCode))
                    {
                        model.ResponseMessage = "Your subscription failed!!";
                        model.Paymentstatus   = CommanClass.PaymentStatus.Failed;
                        return(View(model));
                    }
                }
                //for zarinpal payment plugin
                else
                {
                    //Payment with Zarinpal Service reference.
                    string             authority = string.Empty;
                    int                payment_request_response = 0;
                    PaymentTransaction payment = new PaymentTransaction();
                    try
                    {
                        PaymentGatewayImplementationServicePortTypeClient request = new PaymentGatewayImplementationServicePortTypeClient();
                        Amount = PlanCalculate.CalculatePlanAmount(selectedplan);
                        payment_request_response = request.PaymentRequest(MerchantID, 120, "Test", "", "", ZarinpalCallbackURL, out authority);
                        if (payment_request_response > 0)
                        {
                            if (Request.Files[0].ContentLength > 0)
                            {
                                Guid FileNameGuid = Guid.NewGuid();
                                FileName = FileNameGuid.ToString() + ".html";
                                string _path = Path.Combine(Server.MapPath("~/AdHTML"), FileName);
                                Request.Files[0].SaveAs(_path);
                            }

                            objAdManage             = Mapper.Map <AdManageViewModel, AdManage>(model);
                            objAdManage.Addeddate   = DateTime.Now.Date;
                            objAdManage.RegistAdId  = userid;
                            objAdManage.UpdateDate  = DateTime.Now.Date;
                            objAdManage.UpdatedBy   = userid;
                            objAdManage.UploadFile  = FileName;
                            objAdManage.Description = model.Description;

                            adManageRepository.AddAd(objAdManage);
                            adManageRepository.SaveAll();

                            payment.IsSuccess = false;
                            payment.RegistId  = userid;
                            payment.Authority = authority;
                            payment.Payment_RequestResponse = payment_request_response;
                            payment.Charge_Amount           = Convert.ToInt32(Amount);
                            //Insert in Payment Table
                            Session["IsPaymentPrecessing"] = false;
                            _paymentRepository.InsertPaymentTransactionData(payment);
                            //Redirect to zarinpal gateway site for payment.
                            return(Redirect(ZarinpalPaymentURL + authority));
                        }
                    }
                    catch (Exception ex)
                    {
                        payment.Charge_Amount                = Convert.ToInt32(Amount);
                        payment.IsSuccess                    = false;
                        payment.RegistId                     = userid;
                        payment.Authority                    = authority;
                        payment.Payment_RequestResponse      = payment_request_response;
                        payment.PaymentRequest_ErrorResponse = ex.ToString();
                        _paymentRepository.InsertPaymentTransactionData(payment);
                        Session["PaymentStatus"]       = false;
                        Session["IsPaymentPrecessing"] = false;
                    }
                }

                //Insert in DB
                if (Request.Files[0].ContentLength > 0)
                {
                    //FileName = Convert.ToString(Session["UserId"]) + ".html";
                    Guid FileNameGuid = Guid.NewGuid();
                    FileName = FileNameGuid.ToString() + ".html";
                    string _path = Path.Combine(Server.MapPath("~/AdHTML"), FileName);
                    Request.Files[0].SaveAs(_path);
                }

                // AdManage objAdManage = new AdManage();
                objAdManage             = Mapper.Map <AdManageViewModel, AdManage>(model);
                objAdManage.Addeddate   = DateTime.Now;
                objAdManage.RegistAdId  = Convert.ToInt64(Session["UserId"]);
                objAdManage.UpdateDate  = DateTime.Now;
                objAdManage.UpdatedBy   = Convert.ToInt32(Session["UserId"]);
                objAdManage.UploadFile  = FileName;
                objAdManage.Description = model.Description;

                adManageRepository.AddAd(objAdManage);
                if (adManageRepository.SaveAll())
                {
                    Registration objRegisterUser = registrationRepository.GetClientById(userid);
                    objRegisterUser.PaymentStatus = true;
                    registrationRepository.Edit(objRegisterUser);
                    Session["PaymentStatus"] = true;
                    model.ResponseMessage    = "Your subscription succesfully!!";
                    model.Paymentstatus      = CommanClass.PaymentStatus.Sucess;
                    return(View(model));
                }
                else
                {
                    model.ResponseMessage    = "Your subscription failed!!";
                    model.Paymentstatus      = CommanClass.PaymentStatus.Failed;
                    Session["PaymentStatus"] = false;
                }
            }
            catch (Exception ex)
            {
                //result.Data = "Your subscription failed!! " + ex.Message.ToString();
                model.ResponseMessage    = "Your subscription failed!! " + ex.Message.ToString();
                model.Paymentstatus      = CommanClass.PaymentStatus.Failed;
                Session["PaymentStatus"] = false;
            }

            return(View(model));
        }
        public ActionResult ZarinpalCallback(string Authority = "", string Status = "")
        {
            ShortnerContext   db    = new ShortnerContext();
            AdManageViewModel model = new AdManageViewModel();
            PaymentGatewayImplementationServicePortTypeClient request = new PaymentGatewayImplementationServicePortTypeClient();
            long userid = (long)Session["UserId"];
            PaymentRepository  paymentrepo        = new PaymentRepository(db);
            PaymentTransaction paymenttransaction = new PaymentTransaction();

            long RefID    = 0;
            int  response = 0;

            try
            {
                var RegisteredUser = registrationRepository.GetClientById(userid);
                paymenttransaction = _paymentRepository.GetPaymentByRegistId(userid);

                if (Status == "OK")
                {
                    Amount = PlanCalculate.CalculatePlanAmount(Convert.ToInt32(TempData["PlanAmount"]));

                    //PAYMENT VERIFICATION
                    response = request.PaymentVerification(MerchantID, Authority, 120, out RefID);

                    if (RefID > 0)
                    {
                        //CheckPaymentStatus(Authority);
                        Registration objRegisterUser = registrationRepository.GetClientById(userid);
                        objRegisterUser.PaymentStatus = true;
                        registrationRepository.Edit(objRegisterUser);
                        Session["PaymentStatus"]         = true;
                        model.ResponseMessage            = "Your subscription succesfully!!";
                        model.Paymentstatus              = CommanClass.PaymentStatus.Sucess;
                        paymenttransaction.RegistId      = userid;
                        paymenttransaction.Charge_Paid   = true;
                        paymenttransaction.IsSuccess     = true;
                        paymenttransaction.PaymentMethod = (int)CommanClass.PaymentMethod.Zarinpal;
                        paymenttransaction.Response      = "Complete";
                        paymenttransaction.Status        = Status;
                        paymenttransaction.ReferenceID   = RefID;
                        paymenttransaction.PaymentVerificationResponse = response;
                        paymenttransaction.Charge_Amount = Convert.ToInt32(Amount);
                        _paymentRepository.UpdatePaymentTransactionData(paymenttransaction);

                        RegisteredUser.PaymentStatus = true;
                        registrationRepository.Edit(RegisteredUser);
                        Session["IsPaymentPrecessing"] = true;
                        return(RedirectToAction("Purchase", "Payment", model));
                    }
                }
                if (Status == "NOK")
                {
                    paymenttransaction.RegistId      = userid;
                    paymenttransaction.Charge_Amount = Convert.ToInt32(Amount);
                    paymenttransaction.Charge_Paid   = false;
                    paymenttransaction.ExpireDate    = DateTime.Now.AddDays(30);
                    paymenttransaction.IsSuccess     = false;
                    paymenttransaction.PaymentMethod = (int)CommanClass.PaymentMethod.Zarinpal;
                    paymenttransaction.Response      = "Failed";
                    paymenttransaction.Status        = Status;
                    paymenttransaction.ReferenceID   = RefID;
                    paymenttransaction.Authority     = Authority;
                    paymenttransaction.PaymentVerificationResponse = response;
                    _paymentRepository.UpdatePaymentTransactionData(paymenttransaction);
                    Session["IsPaymentPrecessing"] = false;

                    RegisteredUser.PaymentStatus = false;
                    registrationRepository.Edit(RegisteredUser);

                    model.ResponseMessage    = "Your subscription failed!!";
                    model.Paymentstatus      = CommanClass.PaymentStatus.Failed;
                    Session["PaymentStatus"] = false;
                }
            }
            catch (Exception ex)
            {
                paymenttransaction.RegistId      = userid;
                paymenttransaction.Charge_Amount = Convert.ToInt32(Amount);
                paymenttransaction.Charge_Paid   = false;
                paymenttransaction.IsSuccess     = false;
                paymenttransaction.PaymentMethod = (int)CommanClass.PaymentMethod.Zarinpal;
                paymenttransaction.Response      = "Failed" + ex.ToString();
                paymenttransaction.Status        = Status;
                paymenttransaction.ReferenceID   = RefID;
                paymenttransaction.Authority     = Authority;
                paymenttransaction.PaymentVerificationResponse = Convert.ToInt32(response);
                _paymentRepository.UpdatePaymentTransactionData(paymenttransaction);

                model.ResponseMessage          = "Your subscription failed!" + ex;
                model.Paymentstatus            = CommanClass.PaymentStatus.Failed;
                Session["PaymentStatus"]       = false;
                Session["IsPaymentPrecessing"] = false;
            }
            return(RedirectToAction("Purchase", "Payment", model));
        }
        public ActionResult AdView()
        {
            AdManageViewModel objAdView = new AdManageViewModel();

            return(View(objAdView));
        }
Beispiel #7
0
        public ActionResult Create(AdManageViewModel model, HttpPostedFileBase file)
        {
            string filename     = string.Empty;
            Guid   filenameGuid = Guid.NewGuid();
            //string requesturl = HttpContext.Request.Url.AbsoluteUri.ToString();

            var requesturl = string.Format("{0}://{1}{2}",
                                           HttpContext.Request.Url.Scheme,
                                           HttpContext.Request.Url.Authority, Url.Content("~"));

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                try
                {
                    if (Request.Files[0].ContentLength > 0)
                    {
                        string _path = "";
                        //if (requesturl.Contains(domain_ijli) || requesturl.Contains("https://ijl.li/"))
                        if (requesturl.Contains(domain_ijli))
                        {
                            _path = string.Format(@"{0}AdHTML\\{1}.html", directorypath, filenameGuid.ToString());
                            Request.Files[0].SaveAs(_path);
                        }
                        else
                        {
                            //_path = @"C:\Inetpub\vhosts\aiim.li\httpdocs\UrlShotner\AdHTML\" + filenameGuid.ToString() + ".html";
                            _path = string.Format(@"{0}AdHTML\\{1}.html", directorypath, filenameGuid.ToString());
                            Request.Files[0].SaveAs(_path);
                        }
                    }

                    AdManage objAdManage = new AdManage();
                    objAdManage            = Mapper.Map <AdManageViewModel, AdManage>(model);
                    objAdManage.Addeddate  = DateTime.Now;
                    objAdManage.RegistAdId = Convert.ToInt64(Session["UserId"]);
                    objAdManage.UpdateDate = DateTime.Now;
                    objAdManage.UpdatedBy  = Convert.ToInt32(Session["UserId"]);
                    //objAdManage.UploadFile = Session["UserId"].ToString();
                    objAdManage.UploadFile = filenameGuid.ToString() + ".html";

                    adManageRepository.AddAd(objAdManage);

                    if (adManageRepository.SaveAll())
                    {
                        return(RedirectToAction("Index", "AdManage"));
                    }
                    else
                    {
                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    //throw ex;
                    return(View(model));
                }
            }
        }
Beispiel #8
0
        public ActionResult Create()
        {
            AdManageViewModel objAdManage = new AdManageViewModel();

            return(View(objAdManage));
        }