public BaseAPIController() : base() { lgBus = new LoginBusiness(this.GetContext()); newsBus = new NewsBusiness(this.GetContext()); notiBus = new NotifyBusiness(this.GetContext()); giftBus = new GiftBusiness(this.GetContext()); rqBus = new RequestBusiness(this.GetContext()); cusBus = new CustomerBusiness(this.GetContext()); mBus = new MessageBusiness(this.GetContext()); apiBus = new RequestAPIBusiness(this.GetContext()); pBus = new PointBusiness(this.GetContext()); statisticBus = new StatisticBusiness(this.GetContext()); shopBus = new ShopBusiness(this.GetContext()); itemBus = new ItemBusiness(this.GetContext()); orderBus = new OrderBusiness(this.GetContext()); packBus = new PackageBusiness(this.GetContext()); vnPay = new VNPay(this.GetContext()); }
public BaseController() : base() { loginBusiness = new LoginBusiness(this.GetContext()); batchBusiness = new BatchBusiness(this.GetContext()); cardBusiness = new CardBusiness(this.GetContext()); requestBusiness = new RequestBusiness(this.GetContext()); newsBusiness = new NewsBusiness(this.GetContext()); cusBusiness = new CustomerBusiness(this.GetContext()); rankBusiness = new RankBusiness(this.GetContext()); configBusiness = new ConfigBusiness(this.GetContext()); pointBusiness = new PointBusiness(this.GetContext()); warrantyBusiness = new WarrantyBusiness(this.GetContext()); statisticBus = new StatisticBusiness(this.GetContext()); orderBus = new OrderBusiness(this.GetContext()); userBusiness = new UserBusiness(this.GetContext()); itemBusiness = new ItemBusiness(this.GetContext()); productsBusiness = new ItemBusiness(this.GetContext()); notifyBusiness = new NotifyBusiness(this.GetContext()); shopBusiness = new ShopBusiness(this.GetContext()); agentBusiness = new AgentBusiness(this.GetContext()); vnpay = new VNPay(this.GetContext()); }
public ActionResult Index(OrderInfoModel data) { try { if (String.IsNullOrEmpty(data.CustomerPhone) || String.IsNullOrEmpty(data.CustomerName) || String.IsNullOrEmpty(data.CustomerAddress)) { throw new Exception("Vui lòng điền đầy đủ thông tin trước khi đặt hàng"); } var list = (Session["cart"] as List <PRODUCT>); if (list is null) { throw new Exception("Đơn hàng rỗng không thể thanh toán"); } if (list.Count < 1) { throw new Exception("Đơn hàng rỗng không thể thanh toán"); } using (THUONGMAIDIENTUEntities db = new THUONGMAIDIENTUEntities()) { // tìm và update khách nếu ko thì tạo var customer = db.CUSTOMERs.Where(x => x.CustomerPhone.Equals(data.CustomerPhone)).FirstOrDefault(); if (customer is null) { customer = new CUSTOMER(); customer.CustomerPhone = data.CustomerPhone; customer.CustomerAddress = data.CustomerAddress; customer.CustomerName = data.CustomerName; customer.CustomerEmail = data.CustomerEmail; db.CUSTOMERs.Add(customer); } else { customer.CustomerAddress = data.CustomerAddress; customer.CustomerName = data.CustomerName; customer.CustomerEmail = data.CustomerEmail; } db.SaveChanges(); var giftCode = db.GIFTCODEs.Where(g => g.Code == data.Giftcode).SingleOrDefault(); if (giftCode != null) { giftCode.Status = true;//đã dùng rồi db.SaveChanges(); } ORDER o = new ORDER(); o.IdCustomer = customer.IdCustomer; o.DateOrder = DateTime.Now; o.DateDelivery = DateTime.Now; o.OrderComment = data.CustomerComment; o.IdPayment = data.PaymentMethod; o.IdStatus = 1; int total = 0; foreach (var p in list) { total += (int)p.ProductPrice * p.Quantily; PRODUCT_ORDER po = new PRODUCT_ORDER(); po.Count = (byte)p.Quantily; po.Discount = 0; po.IdProduct = p.IdProduct; po.Price = p.ProductPrice; o.PRODUCT_ORDER.Add(po); } //double total = (double)data.Total; o.Total = total; db.ORDERs.Add(o); db.SaveChanges(); if (data.PaymentMethod == 2) { VNPay vnpay = new VNPay(); string link = vnpay.GetBankingURL(total, data.BankCode, o.IdOrder.ToString(), DateTime.Now); return(Redirect(link)); } TempData["id"] = o.IdOrder; return(RedirectToAction("Success")); } } catch (Exception ex) { ViewBag.Error = ex.Message; } return(View()); }
public ActionResult Thanhcong() { if (Session["cart"] != null) { OrderInfoModel data = new OrderInfoModel(); data.CustomerName = Session["CustomerName"].ToString() == "" ? "" : Session["CustomerName"].ToString(); data.CustomerEmail = Session["CustomerEmail"].ToString() == "" ? "" : Session["CustomerEmail"].ToString(); data.CustomerAddress = Session["CustomerAddress"].ToString() == "" ? "" : Session["CustomerAddress"].ToString(); data.CustomerPhone = Session["CustomerPhone"].ToString() == "" ? "" : Session["CustomerPhone"].ToString(); data.CustomerComment = Session["CustomerComment"].ToString() == "" ? "" : Session["CustomerComment"].ToString(); //data.Giftcode = Session["Giftcode"].ToString() ==null? "": Session["Giftcode"].ToString(); data.PaymentMethod = 3; // nhớ set up 3 trang thai paypal if (String.IsNullOrEmpty(data.CustomerPhone) || String.IsNullOrEmpty(data.CustomerName) || String.IsNullOrEmpty(data.CustomerAddress)) { throw new Exception("Vui lòng điền đầy đủ thông tin trước khi đặt hàng"); } var list = (Session["cart"] as List <PRODUCT>); if (list is null) { throw new Exception("Đơn hàng rỗng không thể thanh toán"); } if (list.Count < 1) { throw new Exception("Đơn hàng rỗng không thể thanh toán"); } using (THUONGMAIDIENTUEntities db = new THUONGMAIDIENTUEntities()) { // tìm và update khách nếu ko thì tạo var customer = db.CUSTOMERs.Where(x => x.CustomerPhone.Equals(data.CustomerPhone)).FirstOrDefault(); if (customer is null) { customer = new CUSTOMER(); } customer.CustomerPhone = data.CustomerPhone; customer.CustomerAddress = data.CustomerAddress; customer.CustomerName = data.CustomerName; customer.CustomerEmail = data.CustomerEmail; if (customer.IdCustomer < 1) { db.CUSTOMERs.Add(customer); } db.SaveChanges(); ORDER o = new ORDER(); o.IdCustomer = customer.IdCustomer; o.DateOrder = DateTime.Now; o.DateDelivery = DateTime.Now; o.OrderComment = data.CustomerComment; o.IdPayment = data.PaymentMethod; // nhớ gán session nhé, để bắt trạng thái thanh toán tùy paypal or ngân lượng vd 3-paypal 4-nganluong o.IdStatus = 1; int total = 0; foreach (var p in list) { total += (int)p.ProductPrice; PRODUCT_ORDER po = new PRODUCT_ORDER(); po.Count = (byte)p.Quantily; po.Discount = 0; po.IdProduct = p.IdProduct; po.Price = p.ProductPrice; o.PRODUCT_ORDER.Add(po); } o.Total = total; db.ORDERs.Add(o); db.SaveChanges(); if (data.PaymentMethod == 2) { VNPay vnpay = new VNPay(); string link = vnpay.GetBankingURL(total, data.BankCode, o.IdOrder.ToString(), DateTime.Now); return(Redirect(link)); } TempData["id"] = o.IdOrder; Session["cart"] = null; return(View()); } } return(Redirect("~/home/index")); }