Esempio n. 1
0
        public ActionResult PayPrice(int post_type = 0, string final_price = "")
        {
            try
            {
                var postType = db.Tbl_PostType.Where(a => a.PostType_Price == post_type).FirstOrDefault();
                if (Session["UserName"] == null)
                {
                    Message = "Access denied. need login.";
                    log.addLog(Message, "Index", "Cart", logStatus.EventLog);
                    return(RedirectToAction("Index", "Account", new { returnUrl = "/Cart/Index" }));
                }
                else
                {
                    var username = Session["UserName"].ToString();

                    var user = db.Tbl_User.Where(a => a.User_Username == username).SingleOrDefault();
                    if (user.User_Address == null || user.User_Address == "")
                    {
                        return(RedirectToAction("EditProfile", "Account"));
                    }
                    //if (PostagePrice == 1)
                    //{
                    //    TempData["PostageType"] = "لطفا نحوه ارسال را انتخاب نمایید.";
                    //    return RedirectToAction("Index", "Cart");
                    //}

                    long allPrice = 0;
                    var  carts    = rep_cart.Get_UserCart(username);
                    foreach (var cart in carts)
                    {
                        allPrice += cart.InterimBill_Price;
                    }
                    //if (allPrice > 300000)
                    //    PostagePrice = 0;

                    Session["AllPrice"] = allPrice + postType.PostType_Price;
                    Tbl_Bill bill = new Tbl_Bill();
                    bill.Bill_Date = DateTime.Now;
                    Random rnd1          = new Random();
                    int    InvoiceNumber = (rnd1.Next(1, 1000) * DateTime.Now.Year) + DateTime.Now.Second;
                    bill.Bill_InvoiceNumber = InvoiceNumber.ToString();
                    bill.Bill_Off           = 0;
                    bill.Bill_OtherPrice    = 0;
                    bill.Bill_PostStatus_ID = 1;
                    //if (allPrice > 300000)
                    //    bill.Bill_PostType_ID = 2;
                    //else
                    bill.Bill_PostType_ID = postType.PostType_ID;
                    bill.Bill_Status      = false;
                    bill.Bill_PayPrice    = Convert.ToInt32(allPrice + postType.PostType_Price);
                    bill.Bill_UserID      = user.User_ID;
                    db.Tbl_Bill.Add(bill);
                    if (Convert.ToBoolean(db.SaveChanges() > 0))
                    {
                        Tbl_UserBills ub = new Tbl_UserBills();
                        foreach (var item in carts)
                        {
                            ub.UserBills_Bill_ID        = bill.Bill_ID;
                            ub.UserBills_InterimBill_ID = item.InterimBill_ID;
                            db.Tbl_UserBills.Add(ub);
                            db.SaveChanges();
                        }

                        try
                        {
                            Session["Bill_ID"] = bill.Bill_ID;
                            //اتصال به درگاه
                            ZarinPal.ZarinPal zarinpal = ZarinPal.ZarinPal.Get();

                            String MerchantID  = "91afdd4e-006f-11ea-bad7-000c295eb8fc";
                            String CallbackURL = "http://www.perfumedecant.ir/Pay/PaymentVerification?billID=" + bill.Bill_ID;
                            //String CallbackURL = "https://localhost:44309/Pay/PaymentVerification?billID=" + bill.Bill_ID;
                            long   Amount      = (long)(allPrice + postType.PostType_Price);
                            String Description = "پرداخت";

                            ZarinPal.PaymentRequest pr = new ZarinPal.PaymentRequest(MerchantID, Amount, CallbackURL, Description);

                            zarinpal.DisableSandboxMode();
                            //zarinpal.EnableSandboxMode();
                            var res = zarinpal.InvokePaymentRequest(pr);


                            if (res.Status == 100)
                            {
                                //Response.Redirect("https://www.zarinpal.com/pg/StartPay/" + Authority + "/Asan");
                                //Response.Redirect("https://www.zarinpal.com/pg/StartPay/" + Authority + "/ZarinGate");
                                Response.Redirect(res.PaymentURL);
                            }
                            else
                            {
                                TempData["PayError"] = "تراکنش با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                                RedirectToAction("Index", "Cart");
                            }
                        }
                        catch
                        {
                            TempData["PayError"] = "تراکنش با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                            return(RedirectToAction("Index", "Cart"));
                        }
                    }
                    TempData["PayError"] = "تراکنش با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                    return(RedirectToAction("Index", "Cart"));
                }
            }
            catch (Exception ex)
            {
                var e = ex.ToString();
                TempData["PayError"] = "تراکنش با موفقیت انجام نشد، لطفا دوباره تلاش کنید.";
                return(RedirectToAction("Index", "Cart"));
            }
        }
        public ActionResult EditOrder(Tbl_UserBills newUserBill)
        {
            String Message = "";

            if (Session["UserName"] == null)
            {
                Message = "Access denied. need login.";
                log.addLog(Message, "EditOrder", "DashboardOrder", logStatus.EventLog);
                return(RedirectToAction("Index", "Account", new { returnUrl = "/Dashboard/Index" }));
            }

            else if (Session["RoleName"].ToString() == "Admin")
            {
                Tbl_UserBills oldUserBill = new Tbl_UserBills();
                try
                {
                    InitDropdownLists();
                    oldUserBill = db.Tbl_UserBills.Where(a => a.UserBills_ID == newUserBill.UserBills_ID).SingleOrDefault();


                    if (oldUserBill == null)
                    {
                        Message = "UserBill with ID" + newUserBill.UserBills_ID + "not found.";
                        log.addLog(Message, "EditUser", "DashboardUser", logStatus.ErrorLog);
                        ViewBag.result = "سفارش یافت نشد.لطفاً دوباره تلاش کنید.";
                        return(RedirectToAction("Index", "DashboardOrder"));
                    }

                    oldUserBill.UserBills_Bill_ID        = newUserBill.UserBills_Bill_ID;
                    oldUserBill.UserBills_InterimBill_ID = newUserBill.UserBills_InterimBill_ID;

                    db.Tbl_UserBills.Attach(oldUserBill);
                    db.Entry(oldUserBill).State = System.Data.Entity.EntityState.Modified;
                    if (Convert.ToBoolean(db.SaveChanges() > 0))
                    {
                        Message = "edited UserBill with id " + newUserBill.UserBills_ID + " done successfully.";
                        log.addLog(Message, "EditOrder", "DashboardOrder", logStatus.EventLog);
                        ViewBag.result = "سفارش با موفقیت ویرایش شد.";
                        return(View(newUserBill));
                    }
                    else
                    {
                        Message = "edited UserBill with id " + newUserBill.UserBills_ID + " failed.";
                        log.addLog(Message, "EditOrder", "DashboardOrder", logStatus.ErrorLog);
                        ViewBag.result = "سفارش ویرایش نشد، لطفا دوباره تلاش کنید.";
                        return(View(newUserBill));
                    }
                }
                catch
                {
                    Message = "edited UserBill with id " + newUserBill.UserBills_ID + " failed.";
                    log.addLog(Message, "EditOrder", "DashboardOrder", logStatus.ErrorLog);
                    ViewBag.result = "سفارش ویرایش نشد، لطفا دوباره تلاش کنید.";
                    return(View(newUserBill));
                }
            }
            else
            {
                Message = "You do not have access to this page.";
                log.addLog(Message, "EditOrder", "DashboardOrder", logStatus.EventLog);
                return(RedirectToAction("Error404", "Home"));
            }
        }