public ActionResult ValidateCommand(string pack, string quantity, string coin, string cointotal, string totalPrice) { if (User.IsInRole("Merchant")) { bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSandbox"]); PayPalModel paypal = new PayPalModel(useSandbox); paypal.item_name = "CoinPack " + pack; paypal.coin = coin; paypal.cointotal = cointotal; paypal.price = pack; paypal.quantity = quantity; paypal.amount = totalPrice; string user_id = User.Identity.GetUserId(); paypal.merchant = db.Merchants.Include(a => a.AspNetUser).Where(a => a.UserID == user_id).FirstOrDefault(); //lưu data MerchantPayment mp = new MerchantPayment(); mp.MerchantID = paypal.merchant.MerchantID; mp.QuantityPack = Convert.ToInt32(quantity); mp.PriceTotal = Convert.ToDecimal(totalPrice); mp.Created = DateTime.Now; mp.StartusID = 0;//0: chưa thanh toán mp.CoinPackID = db.CoinPacks.Where(a => a.Coin.ToString() == coin).Select(a => a.CoinPackID).FirstOrDefault(); db.MerchantPayments.Add(mp); db.SaveChanges(); //lưu vào activitymerchant ActivityMerchant am = new ActivityMerchant(); am.MerchantID = mp.MerchantID; am.Object = "Order" + mp.PaymentID; am.Description = "Tạo đơn hàng mua Coin"; am.ActivityDate = mp.Created; db.ActivityMerchants.Add(am); paypal.paymentID = mp.PaymentID.ToString(); paypal.date = mp.Created.ToString(); db.SaveChanges(); return(View(paypal)); } else { return(RedirectToAction("Shop", "Home", new { area = "" })); } }
public ActionResult SuccessFromPaypal(string id, int coin) { if (User.IsInRole("Merchant")) { SetCallout("Giao dịch thành công!", "success"); var mp = db.MerchantPayments.Where(a => a.PaymentID.ToString() == id).FirstOrDefault(); mp.StartusID = 1;// 1: giao dịch thành công db.Entry(mp).State = EntityState.Modified; //lưu vào activitymerchant ActivityMerchant am = new ActivityMerchant(); am.MerchantID = mp.MerchantID; am.Object = "Order" + mp.PaymentID; am.Description = "Hoàn tất thanh toán đơn hàng mua Coin"; am.ActivityDate = DateTime.Now; db.ActivityMerchants.Add(am); //lưu vào historyusecoin HistoryUseCoin huc = new HistoryUseCoin(); huc.MerchantID = mp.MerchantID; huc.PaymentID = mp.PaymentID; huc.Description = "Đã mua"; huc.Coin = coin; huc.Created = am.ActivityDate; db.HistoryUseCoins.Add(huc); //cộng coin cho merchant var m = db.Merchants.Where(a => a.MerchantID == mp.MerchantID).FirstOrDefault(); if (m.Coin == null || m.Coin == 0) { m.Coin = coin; } else { m.Coin = m.Coin + coin; } db.Entry(m).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index2", "Coin")); } else { return(RedirectToAction("Shop", "Home", new { area = "" })); } }
public ActionResult CancelFromPaypal(string id) { if (User.IsInRole("Merchant")) { SetCallout("Giao dịch đã được hủy!", "warning"); var mp = db.MerchantPayments.Where(a => a.PaymentID.ToString() == id).FirstOrDefault(); mp.StartusID = 2; // 2: giao dịch bị hủy //lưu vào activitymerchant ActivityMerchant am = new ActivityMerchant(); am.MerchantID = mp.MerchantID; am.Object = "Order" + mp.PaymentID; am.Description = "Hủy đơn hàng mua Coin"; am.ActivityDate = DateTime.Now; db.ActivityMerchants.Add(am); db.Entry(mp).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index2", "Coin")); } else { return(RedirectToAction("Shop", "Home", new { area = "" })); } }