コード例 #1
0
 public static Bill MapFrom(this Tbl_Bill bill)
 {
     return(new Bill
     {
         Id = bill.Id,
         Number = bill.Number,
         VendorId = bill.VendorId,
         VendorName = bill.Tbl_Vendor?.Name ?? string.Empty,
         Amount = bill.Amount,
         BillDate = bill.BillDate,
         DueDate = bill.DueDate,
         Status = bill.Status,
         Created_At = bill.Created_At,
         Updated_At = bill.Updated_At,
         CurrencyId = bill.CurrencyId,
         CurrencyName = bill.Tbl_Currency?.Name ?? string.Empty,
         Notes = bill.Notes,
         OrderNumber = bill.OrderNumber,
         CategoryId = bill.CategoryId,
         CategoryName = bill.Tbl_Category?.Name ?? string.Empty,
         Recurring = bill.Recurring,
         Attachment = bill.Attachment,
         SubTotal = bill.SubTotal,
         Discount = bill.Discount,
         Tax = bill.Tax,
         GrandTotal = bill.GrandTotal,
         Discount_Percentage = bill.Discount_Percentage,
         CurrencySymbol = bill.Tbl_Currency?.Symbol ?? string.Empty,
         SymbolPosition = bill.Tbl_Currency?.SymbolPosition ?? string.Empty,
         Bill_Items = bill.Tbl_Bill_Items?.Select(x => x.MapFrom()).ToList()
     });
 }
コード例 #2
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"));
            }
        }