public ActionResult Payment(string shipName, string mobile, string email, string address) { var id = (long)-1; decimal total = 0; var order = new ORDER(); var user = (UserLogin)Session[CommonStants.USER_SESSION]; if (user != null) { order.CUSTOMERID = user.userID; } order.CREATEDATE = DateTime.Now; order.SHIPDDRESS = address; order.SHIPNAME = shipName; order.SHIPMOBILE = mobile; order.SHIPEMAIL = email; try { id = new OrderDAO().Insert(order); var sessionCart = (List <CartItem>)Session[CartSession]; var orderDetailDAO = new OrderDetailDAO(); foreach (var item in sessionCart) { var orderDetail = new ORDERDETAIL(); orderDetail.PRODUCTID = item.Product.SANPHAM_ID; orderDetail.GIAMGIA = item.Product.KHUYENMAI; orderDetail.ORDERID = id; orderDetail.PRICE = (long)item.Product.GIA_SANPHAM; orderDetail.QUANTITY = item.Quantity; orderDetailDAO.Insert(orderDetail); total += (item.Product.GIA_SANPHAM * item.Quantity); } string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/client/teamplet/NewOrder.html")); content = content.Replace("{{customereName}}", shipName); content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", total.ToString("N0")); var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"]; new MailHelper().SenMail(toEmail, "Đơn hàng mới từ Shop", content); new MailHelper().SenMail(email, "Đơn hàng mới từ Shop", content); Session[CartSession] = null; } catch (Exception e) { return(Redirect("/loi-thanh-toan")); } return(Redirect("/hoan-thanh?id=" + id)); }
public bool Insert(ORDERDETAIL detail) { try { db.ORDERDETAILs.Add(detail); db.SaveChanges(); return(true); } catch { return(false); } }
public JsonResult CreateOrder(string orderViewModel) { var order = new JavaScriptSerializer().Deserialize <OrderViewModel>(orderViewModel); var orderDao = new OrderDao(); var orderNew = new ORDER(); orderNew.CretedDate = DateTime.Now; orderNew.ShipAddress = order.CustomerAddress; orderNew.ShipMobile = order.CustomerMobile; orderNew.ShipName = order.CustomerName; orderNew.ShipEmail = order.CustomerEmail; orderNew.CustomerMessage = order.CustomerMessage; orderNew.PaymentMethod = order.PaymentMethod; orderNew.PaymentStatus = order.PaymentStatus; orderNew.Status = true; orderDao.Insert(orderNew); var detailDao = new OrderDetailDao(); var sessionCart = (List <CartItem>)Session[CommonConstants.CartSession]; decimal total = 0; foreach (var item in sessionCart) { var detail = new ORDERDETAIL(); detail.OrderID = orderNew.ID; detail.ProductID = item.Product.ID; detail.Quantity = item.Quantity; if (item.Product.PromotionPrice.HasValue) { detail.Price = item.Product.PromotionPrice.Value; total += (item.Product.PromotionPrice.GetValueOrDefault(0) * item.Quantity); } else { detail.Price = item.Product.Price; total += (item.Product.Price.Value * item.Quantity); } detailDao.Insert(detail); } string content = System.IO.File.ReadAllText(Server.MapPath("~/Areas/Client/template/neworder.html")); content = content.Replace("{{CustomerName}}", order.CustomerName); content = content.Replace("{{Phone}}", order.CustomerMobile); content = content.Replace("{{Email}}", order.CustomerEmail); content = content.Replace("{{Address}}", order.CustomerAddress); content = content.Replace("{{Total}}", total.ToString("N0")); new MailHelper().SendMail(order.CustomerEmail, "Thông tin đơn đặt hàng từ T&Q", content); Session[CommonConstants.CartSession] = null; return(Json(new { status = true })); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var order = new ORDER(); order.CretedDate = DateTime.Now; order.ShipAddress = address; order.ShipMobile = mobile; order.ShipName = shipName; order.ShipEmail = email; try { var id = new OrderDao().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detailDao = new Model.DAO.OrderDetailDao(); decimal total = 0; foreach (var item in cart) { var orderDetail = new ORDERDETAIL(); orderDetail.ProductID = item.Product.ID; orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.Quantity = item.Quantity; detailDao.Insert(orderDetail); total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity); } string content = System.IO.File.ReadAllText(Server.MapPath("~/Areas/Client/template/neworder.html")); content = content.Replace("{{CustomerName}}", shipName); content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", total.ToString("N0")); var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); new MailHelper().SendMail(email, "Đơn hàng mới từ Basic", content); new MailHelper().SendMail(toEmail, "Đơn hàng mới từ Basic", content); } catch (Exception) { //ghi log return(Redirect("/loi-thanh-toan.html")); } return(Redirect("/hoan-thanh.html")); }
public async Task <int> AddOrderDetail(int OrderID, int ProductID, int Quanity) { try { var order = new ORDERDETAIL() { OrderID = OrderID, ProductID = ProductID, Quantity = Quanity }; db.ORDERDETAILs.Add(order); await db.SaveChangesAsync(); return(order.DetailID); } catch { return(0); } }
protected void btnPayment_Click(object sender, EventArgs e) { GalleryEntities1 _db = new GalleryEntities1(); ShoppingCart cs = new ShoppingCart(); List <CARTITEM> orderItem = cs.GetCartItems(); ORDER order = new ORDER { date = DateTime.Now, discount = 0, UserId = (Guid)u.ProviderUserKey, //PaymentId = null, status = "pending" }; _db.ORDERs.Add(order); _db.SaveChanges(); for (int i = 0; i < orderItem.Count(); i++) { ORDERDETAIL orderDetail = new ORDERDETAIL(); orderDetail.ProductId = orderItem[i].ProductId; orderDetail.OrderId = order.OrderId; orderDetail.Quantity = orderItem[i].Quantity; orderDetail.TotalPrice = (orderItem[i].Quantity * _db.PRODUCTs.Find(orderItem[i].ProductId).Price); _db.ORDERDETAILs.Add(orderDetail); _db.SaveChanges(); } Session["total"] = cs.GetTotal().ToString(); Session["orderid"] = order.OrderId.ToString(); Response.Redirect("~/Payment.aspx"); }
public ActionResult ThanhToanTT() { var sessionCart = (List <CartItem>)Session[CommonConstants.CartSession]; var orderNew = new ORDER(); decimal total = 0; foreach (var item in sessionCart) { var detail = new ORDERDETAIL(); detail.OrderID = orderNew.ID; detail.ProductID = item.Product.ID; detail.Quantity = item.Quantity; if (item.Product.PromotionPrice.HasValue) { detail.Price = item.Product.PromotionPrice.Value; total += (item.Product.PromotionPrice.GetValueOrDefault(0) * item.Quantity); } else { detail.Price = item.Product.Price; total += (item.Product.Price.Value * item.Quantity); } } decimal totals = total * 100; var id = sessionCart.ToList().LastOrDefault(); string text = ""; foreach (var cart in sessionCart) { text = text + cart.Product.Name + " " + cart.Product.Quantity; if (cart.Product.ID != id.Product.ID) { text = text + " + "; } } Session[CommonConstants.CartSession] = null; string SECURE_SECRET = "A3EFDFABA8653DF2342E8DAC29B51AF0"; // Khoi tao lop thu vien va gan gia tri cac tham so gui sang cong thanh toan VPCRequest conn = new VPCRequest("https://mtf.onepay.vn/onecomm-pay/vpc.op"); conn.SetSecureSecret(SECURE_SECRET); // Add the Digital Order Fields for the functionality you wish to use // Core Transaction Fields conn.AddDigitalOrderField("Title", "onepay paygate"); conn.AddDigitalOrderField("vpc_Locale", "vn");//Chon ngon ngu hien thi tren cong thanh toan (vn/en) conn.AddDigitalOrderField("vpc_Version", "2"); conn.AddDigitalOrderField("vpc_Command", "pay"); conn.AddDigitalOrderField("vpc_Merchant", "ONEPAY"); conn.AddDigitalOrderField("vpc_AccessCode", "D67342C2"); conn.AddDigitalOrderField("vpc_MerchTxnRef", MaHoaMD5(ngaunhien().ToString())); conn.AddDigitalOrderField("vpc_OrderInfo", text); conn.AddDigitalOrderField("vpc_Amount", totals.ToString()); conn.AddDigitalOrderField("vpc_Currency", "VND"); conn.AddDigitalOrderField("vpc_ReturnURL", Url.Action("Index", "TrangChu", null, Request.Url.Scheme)); // Thong tin them ve khach hang. De trong neu khong co thong tin conn.AddDigitalOrderField("vpc_SHIP_Street01", ""); conn.AddDigitalOrderField("vpc_SHIP_Provice", ""); conn.AddDigitalOrderField("vpc_SHIP_City", ""); conn.AddDigitalOrderField("vpc_SHIP_Country", "Vietnam"); conn.AddDigitalOrderField("vpc_Customer_Phone", ""); conn.AddDigitalOrderField("vpc_Customer_Email", ""); conn.AddDigitalOrderField("vpc_Customer_Id", "onepay_paygate"); // Dia chi IP cua khach hang conn.AddDigitalOrderField("vpc_TicketNo", ""); // Chuyen huong trinh duyet sang cong thanh toan String url = conn.Create3PartyQueryString(); return(Redirect(url)); }
public static bool Insert(int userId, String fullName, String address, String tel, DateTime orrdertime, String note, int state, int totalpayent, int idCity, int idDistrict, List<int> foods, List<int> count) { //Khởi tạo một đối tượng ACCOUNT bool flag = true; _db = new FoodStoreEntities(); int id = GetMaxId(); ORDER currentorder = null; var orderdetails = new List<ORDERDETAIL>(); ACCOUNT account = AccountController.GetById(userId, _db); CITY city = CityController.GetById(idCity, _db); DISTRICT district = DistrictController.GetById(idDistrict, _db); try { var order = new ORDER { ID = id, ACCOUNT = account, Name = fullName, Tel = tel, Address = address, Date = orrdertime, Note = note, State = state, TotalPayment = totalpayent, DISTRICT = district, CITY = city }; _db.ORDERs.AddObject(order); _db.SaveChanges(); int n = foods.Count(); for (int i = 0; i < n; i++) { int fId = foods[i]; FOOD food = FoodController.GetById(fId, _db); currentorder = GetById(id, _db); var orderdetail = new ORDERDETAIL { ID = OrderDetailController.GetMaxId(), ORDER = currentorder, FOOD = food, Count = count[i], TotalPayment = count[i]*food.Price, Price = food.Price }; orderdetails.Add(orderdetail); _db.ORDERDETAILs.AddObject(orderdetail); _db.SaveChanges(); } _db.AcceptAllChanges(); } catch (Exception) { flag = false; throw; } if (flag) { StringBuilder body = new StringBuilder() .AppendLine("A new order has been submitted") .AppendLine("---") .AppendLine("Items:"); foreach (ORDERDETAIL i in orderdetails) { int? subtotal = i.Price*i.Count; body.AppendFormat("{0} x {1} (subtotal: {2:c})", i.Count, i.FOOD.Name, subtotal).AppendLine(); } body.AppendLine() .AppendFormat("Total order value: {0:c}", ((int)currentorder.TotalPayment).ToString("c")) .AppendLine("---") .AppendLine("Ship to:") .AppendLine(currentorder.Name) .AppendLine(currentorder.Note) .AppendLine(currentorder.Tel) .AppendLine(currentorder.Address) .AppendLine(currentorder.DISTRICT.Name) .AppendLine(currentorder.CITY.Name) .AppendLine("---"); Mail.SendOrderDetail(currentorder.Note, currentorder.Name, body); } return flag; }