protected void btnOrder_Click(object sender, EventArgs e) { Order o = new Order(); o.OrderDate = DateTime.Now; o.FirstName = txtFirstName.Text.Trim(); o.LastName = txtLastName.Text.Trim(); o.Email = txtEmail.Text.Trim(); o.PhoneNumber = txtPhone.Text.Trim(); o.Address = txtAddress.Text.Trim(); o.Province = txtProvince.Text.Trim(); o.City = txtCity.Text.Trim(); o.Country = txtCountry.Text.Trim(); o.Total = float.Parse(Session["totalCart"].ToString()); o.Shipment = new Shipment(); o.Shipment.ID = int.Parse(cbShipment.SelectedValue); if (OrderDAO.Insert(o)) { List <Product> Cart = Session["Cart"] as List <Product>; foreach (Product p in Cart) { OrderDetail od = new OrderDetail(); od.Product = p; od.Order = new Order(); od.Order.ID = OrderDAO.GetMaxID(); OrderDetailDAO.Insert(od); } Session.Abandon(); Session.Clear(); Session.Add("totalCart", 0); Session.Add("Cart", new List <Product>()); Response.Redirect("OrderCompleteGUI.aspx"); } }
public async Task <JsonResult> SubmitCheckoutCustomer(CheckoutModel model) { try { var customer = await new CustomerDAO().LoadByUsername(HttpContext.User.Identity.Name); var order = await new OrderDAO().AddOrderCustomer(customer.CustomerID, model.CustomerName, model.CustomerAddress, model.CustomerPhone, await GetTotal()); if (order != 0) { try { var orderdetail = new OrderDetailDAO(); foreach (var item in (List <CartItemModel>)Session["cart"]) { await orderdetail.AddOrderDetail(order, item.product.ProductID, item.quantity); } Session["cart"] = null; return(Json(new { Success = true, ID = order }, JsonRequestBehavior.AllowGet)); } catch { var result = await new OrderDAO().DeleteOrder(order); return(Json(new { Success = false, error = "error creating order details" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ThanhToan(string shipname, string shipmobile, string shipemail, string shipaddress) { var session = (Common.LoginDetail)Session[Common.CommonConstants.USER_SESSION]; var order = new Order(); order.CreatedDate = DateTime.Now; order.ShipName = shipname; order.ShipMobile = shipmobile; order.ShipEmail = shipemail; order.ShipAddress = shipaddress; order.Status = 1; order.CustomerID = session.User.ID; try { var orderdao = new OrderDAO(); var id = orderdao.Insert(order); var cart = (List <GioHangViewModel>)Session[CommonConstants.CartSession]; var orderdetaildao = new OrderDetailDAO(); decimal?total = 0; foreach (var item in cart) { var orderdetail = new OrderDetail(); orderdetail.ProductID = item.Product.ID; orderdetail.OrderID = (int)id; orderdetail.Quantity = item.Quantity; if (item.Product.PromotionPrice != null) { orderdetail.Price = item.Product.PromotionPrice * item.Quantity; total += (item.Product.PromotionPrice.GetValueOrDefault(0) * item.Quantity); } else { orderdetail.Price = item.Product.Price * item.Quantity; total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity); } orderdetaildao.Insert(orderdetail); } //string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/website/template/neworder.html")); //content = content.Replace("{{CustomerName}}", shipname); //content = content.Replace("{{Phone}}", shipmobile); //content = content.Replace("{{Email}}", shipemail); //content = content.Replace("{{Address}}", shipaddress); //content = content.Replace("{{Total}}", total.Value.ToString("#,##0 ₫").Replace(',', '.')); //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); //new MailHelper().SendMail(shipemail, "Đơn hàng mới từ HomeShoppe", content); //new MailHelper().SendMail(toEmail, "Đơn hàng mới từ HomeShoppe", content); } catch (Exception ex) { return(Redirect("/loi-thanh-toan")); } Session[CommonConstants.CartSession] = null; return(Redirect("/hoan-thanh-thanh-toan/" + order.ID)); }
public async Task <JsonResult> SubmitCheckout(CheckoutModel model) { try { if (ModelState.IsValid) { var order = await new OrderDAO().AddOrder(model.CustomerName, model.CustomerAddress, model.CustomerPhone, await GetTotal()); if (order != 0) { try { var orderdetail = new OrderDetailDAO(); foreach (var item in (List <CartSession>)Session["cart"]) { await orderdetail.AddOrderDetail(order, item.ProductID, item.Quantity); } Session["cart"] = null; return(Json(new { Success = true, ID = order }, JsonRequestBehavior.AllowGet)); } catch { var result = await new OrderDAO().DeleteOrder(order); return(Json(new { Success = false, error = "error creating order details" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { Success = false }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Payment(string name, string mobile, string address, string email) { var order = new Order() { CreatedDate = DateTime.Now, ShipAddress = address, ShipMobile = mobile, ShipName = name, ShipEmail = email }; int total = 0; var orderID = new OrderDAO().Insert(order); if (orderID > 0) { var cart = (List <CartItem>)Session[CartSession]; var orderDetailDAO = new OrderDetailDAO(); foreach (var item in cart) { var orderDetail = new OrderDetail() { ProductID = item.Product.ID, OrderID = orderID, Price = item.Product.Price, Quantity = item.Quantity }; orderDetailDAO.Insert(orderDetail); total += (int)item.Product.Price.GetValueOrDefault(0) * item.Quantity; } } string content = System.IO.File.ReadAllText(Server.MapPath(@"\Assets\Client\newOrder.html")); content = content.Replace("{{CustomerName}}", name); content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", total.ToString("N0")); new MailHelper().SendMail(email, "Đơn hàng mới", content); return(Redirect("/hoan-thanh")); }
// GET: Admin/OrderDetail public ActionResult Index(int id) { List <OrderDetailJoinProduct> order = new List <OrderDetailJoinProduct>(); order = new OrderDetailDAO().getOrderDetail(id); return(View(order)); }
public ActionResult Checkout(string username, string address, string note, int?payment) { if (address.Trim().Length == 0) { TempData["ErrorMess"] = "Please enter your address."; return(RedirectToAction("Checkout")); } if (payment.ToString().Length == 0) { TempData["ErrorMess"] = "Please choose your form of payment!"; return(RedirectToAction("Checkout")); } var order = new Orders(); order.Username = username; order.ShippedAddress = address; order.Note = note; order.PaymentID = payment; order.CreationDate = DateTime.Now; order.Status = 0; var orderDAO = new OrderDAO(); var productDAO = new ProductDAO(); var orderDetailDAO = new OrderDetailDAO(); try { var id = orderDAO.Insert(order); var cart = (List <CartItem>)Session[CommonConstants.CartSession]; foreach (var item in cart) { var orderDetail = new OrderDetails(); orderDetail.OrderID = (int)id; orderDetail.ProductID = item.Product.ProductID; orderDetail.UnitPrice = item.Product.UnitPrice; orderDetail.Quantity = item.Quantity; if (!productDAO.ValidateCheckOut(orderDetail.ProductID, orderDetail.Quantity.GetValueOrDefault(0))) { TempData["ErrorMess"] = orderDetail.Products.ProductName + "is in stock less than the quantity you ordered. Please reduce the quantity!"; return(RedirectToAction("Checkout")); } orderDetailDAO.Insert(orderDetail); var isSuccess = new ProductDAO().UpdateUnitOnOder(orderDetail.ProductID, orderDetail.Quantity.GetValueOrDefault(0)); if (!isSuccess) { return(RedirectToAction("Error")); } } } catch (Exception) { return(Redirect("cart")); } Session[CommonConstants.CartSession] = null; return(RedirectToAction("Success")); }
// GET: Admin/OrderDetail public ActionResult Index(string searchString, int page = 1, int pageSize = 10) { var DAO = new OrderDetailDAO(); var model = DAO.ListAllOrderDetail(searchString, page, pageSize); ViewBag.SearchString = searchString; return(View(model)); }
public ActionResult OrderDetailManager(long idShopOrder) { var orderDetails = new OrderDetailDAO().ListByIdShopOrder(idShopOrder); ViewBag.Customer = new TotalOrderDAO().GetDetail(orderDetails.FirstOrDefault().ShopOrder.IDTotalOrder.Value); ViewBag.ShopOrder = new ShopOrderDAO().GetDetail(idShopOrder); return(View(orderDetails)); }
public JsonResult ChangeStatus(long id) { var result = new OrderDetailDAO().ChangeStatus(id); return(Json(new { status = result })); }
public ActionResult Index(string txtName, string txtEmail, string txtAddress, string txtPhoneNumber) { var sessionCart = Session[Constant.CART_ITEM]; if (sessionCart == null || ((List <CartItem>)sessionCart).Count == 0) { TempData["AlertMessage"] = "Chưa có sản phẩm trong giỏ hàng!"; TempData["AlertType"] = "alert-warning"; return(RedirectToAction("Index")); } var sessionClient = Session[Constant.CLIENT_SESSION]; if (sessionClient == null) { TempData["AlertMessage"] = "Bạn phải đăng nhập trước!"; TempData["AlertType"] = "alert-warning"; return(RedirectToAction("Index")); } OrderDAO orderDAO = new OrderDAO(); long userID = ((UserLogin)sessionClient).UserID; DateTime now = DateTime.Now; long orderID = orderDAO.getLastID() + 1; orderDAO.Insert(new Order() { ID = orderID, UserID = userID, Paid = false, OrderDate = now, DeliveryStatus = "Chưa giao hàng", DeliveryDate = now.AddDays(10), DeliveryAddress = txtAddress }); List <CartItem> ls = (List <CartItem>)sessionCart; OrderDetailDAO dao = new OrderDetailDAO(); BookDAO bookDAO = new BookDAO(); foreach (var item in ls) { dao.Insert(new OrderDetail() { BookID = item.BookPur.ID, OrderID = orderID, Price = item.BookPur.Price, Quantity = item.Quantity }); bookDAO.SaleBook(item.BookPur.ID, item.Quantity); } TempData["AlertMessage"] = "Đặt hàng thành công"; TempData["AlertType"] = "alert-success"; Session[Constant.CART_ITEM] = new List <CartItem>(); return(RedirectToAction("Index")); }
public async Task <JsonResult> SubmitCheckout(CheckoutModel model) { try { if (ModelState.IsValid) { var orderid = await new OrderDAO().AddOrder(model.CustomerName, model.CustomerAddress, model.CustomerPhone, await GetTotal()); if (orderid != 0) { try { var orderdetail = new OrderDetailDAO(); foreach (var item in (List <CartItemModel>)Session["cart"]) { await orderdetail.AddOrderDetail(orderid, item.product.ProductID, item.quantity); } Session["cart"] = null; return(Json(new JsonStatus() { Status = true, Message = orderid.ToString() }, JsonRequestBehavior.AllowGet)); //return Json(new { Success = true, ID = orderid }, JsonRequestBehavior.AllowGet); } catch { var result = await new OrderDAO().DeleteOrder(orderid); return(Json(new JsonStatus() { Status = false, Message = "error creating order details" }, JsonRequestBehavior.AllowGet)); //return Json(new { Success = false, error = "error creating order details" }, JsonRequestBehavior.AllowGet); } } return(Json(new JsonStatus() { Status = false, Message = "Fail create order" }, JsonRequestBehavior.AllowGet)); } return(Json(new JsonStatus() { Status = false, Message = "Model State no valid" }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new JsonStatus() { Status = false, Message = "Error" }, JsonRequestBehavior.AllowGet)); } }
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 ActionResult PaypalPaymanet() { var s = PdtHolder.Success(Request.QueryString.Get("tx")); //khởi tạo biến order var order = new Order(); var username = Session["UsernameMember"]; if (username != null) { var model = new UserDAO().findByUsername(username.ToString()); order.UserID = model.ID; } order.ShipCreateDate = DateTime.Now; order.ShipName = s.AddressName; order.ShipAddress = s.AddressState + "-" + s.AddressCountry + "-" + s.AddressStreet; order.ShipEmail = s.PayerEmail; order.Status = 0; order.PaymentID = 1; //insert order var id = new OrderDAO().Create(order);//trả về id của order try { var cart = (List <CartItem>)Session[CartSession]; var db = new OrderDetailDAO(); foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.ProductModel.ID; orderDetail.OrderID = id; if (item.ProductModel.Sale != null) { orderDetail.Price = item.ProductModel.Sale; } else { orderDetail.Price = item.ProductModel.Price; } orderDetail.Quantity = item.Quantity; db.Create(orderDetail); Session[CartSession] = null; } EmailTool emailTool = new EmailTool(); emailTool.SendMail(GetParent(id)); } catch (Exception) { throw; } return(RedirectToAction("Success", "Cart"));//chuyển hướng đến hành động được chỉ định thay vì hiển thị HTML }
public ActionResult OrderDetail(int id) { var dao = new OrderDetailDAO(); var order = dao.getOrderDetailByID(id); CultureInfo cul = CultureInfo.GetCultureInfo("vi-VN"); order.TotalCostString = double.Parse(order.TotalCost.ToString()).ToString("#,###", cul.NumberFormat); ViewBag.Order = order; ViewBag.ListBook = dao.getListBookOfOder(id); return(View()); }
public ActionResult HoanThanh(int orderID) { var orderdao = new OrderDAO(); ViewBag.ViewOrder = orderdao.ViewOrder(orderID); var orderdetaildao = new OrderDetailDAO(); var list = orderdetaildao.List(orderID); return(View(list)); }
public ActionResult Payment(long customerID, decimal?TotalMoney, string shipName, string mobile, string address) { var totalorderdao = new TotalOrderDAO(); var totalorder = new TotalOrder(); totalorder.CustomerID = customerID; totalorder.CreateDate = DateTime.Now; totalorder.CustomerName = shipName; totalorder.Phone = mobile; totalorder.Address = address; totalorder.TotalPrice = TotalMoney; totalorder.Status = 0; try { var idTotalOrder = totalorderdao.Insert(totalorder); var cart = (List <CartItem>)Session[CartSession]; var listshopID = cart.GroupBy(x => x.Product.CreateBy).Select(group => new { ID = group.Key }); foreach (var shop in listshopID) { var shoporderdao = new ShopOrderDAO(); var shoporder = new ShopOrder(); shoporder.IDTotalOrder = idTotalOrder; shoporder.IDMerchant = shop.ID; shoporder.Status = 0; var idShopoder = shoporderdao.Insert(shoporder); decimal?tongtienshop = 0; foreach (var detail in cart) { if (detail.Product.CreateBy == shop.ID) { var detailorderdao = new OrderDetailDAO(); var detailorder = new OrderDetail(); detailorder.IDProduct = detail.Product.ID; detailorder.Price = detail.Product.Price; detailorder.Quantity = detail.Quantity; detailorder.IDShopOrder = idShopoder; tongtienshop += detailorder.Price * detailorder.Quantity; detailorderdao.Insert(detailorder); } new ProductDAO().UpdateQuantity(detail.Product.ID, detail.Quantity); } shoporderdao.UpdateTotalPrice(idShopoder, tongtienshop); } } catch (Exception ex) { // de cho vui return(Redirect("/loi-thanh-toan")); } Session[CartSession] = null; new ProductDAO().SetProductOutOfStock(); return(RedirectToAction("SuccessPayment")); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var order = new Order(); order.CreatedDate = DateTime.Now; order.ShipName = shipName; order.ShipMobile = mobile; order.ShipAddress = address; order.ShipEmail = email; // tổng tiền decimal Total = 0; try { // thêm vào 1 order, trả về id của order vừa thêm var id = new OrderDAO().Insert(order); var sessionCart = (List <CartItem>)Session[CartSession]; var detailDAO = new OrderDetailDAO(); // lặp qua tất cả các mặt hàng lấy ra detail foreach (var item in sessionCart) { var orderDetail = new OrderDetail(); orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.ProductID = item.Product.ID; orderDetail.Quantity = item.Quantity; detailDAO.Insert(orderDetail); Total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity); } // lấy ra content của trang template đã tạo string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/client/template/newOrder.html")); // thay đổi lại các giá trị cho nó content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{CustomerName}}", shipName); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", Total.ToString()); var toEmail = ConfigurationManager.AppSettings["ToEmail"].ToString(); new MailHelper().SendMail(toEmail, "Đơn hàng mới", content); } catch (Exception ex) { return(Redirect("/error")); } return(Redirect("/hoan-thanh")); }
protected void tblOrders_SelectedIndexChanged(object sender, EventArgs e) { int id = int.Parse(tblOrders.SelectedDataKey.Value.ToString()); lblOrderDetail.Visible = true; Order o = new Order(); o.ID = id; DataTable dt = OrderDetailDAO.GeDataTable(o); tblOrderDetails.DataSource = dt; tblOrderDetails.DataBind(); }
public ActionResult PaymentUserLogin() { var username = Session["Member"];//lấy session gáng giá trị vào order var model = new UserDAO().FindUserName(username.ToString()); var order = new Order(); order.ShipCreateDate = DateTime.Now; order.ShipName = model.Name; order.ShipAddress = model.Address; order.ShipEmail = model.Email; order.ShipPhone = model.Phone; order.Status = 0; order.UserID = model.ID; //insert order var id = new OrderDAO().Create(order);//trả về id của order try { var cart = (List <CartItem>)Session[CartSession]; var db = new OrderDetailDAO(); decimal total = 0; foreach (var item in cart) { decimal price = (decimal)item.ProductModel.Price; var orderDetail = new OrderDetail(); orderDetail.ProductID = item.ProductModel.ID; orderDetail.OrderID = id; if (item.ProductModel.Sale.HasValue) { price = price - (decimal)(item.ProductModel.Sale * price / 100); } orderDetail.Price = price; orderDetail.Quantity = item.Quantity; orderDetail.SubPrice = item.Quantity * price; total += (decimal)orderDetail.SubPrice; db.Create(orderDetail); Session[CartSession] = null; } new OrderDAO().EditTotal(total, id); EmailTool emailTool = new EmailTool(); emailTool.SendMail(GetParent(id)); } catch (Exception) { throw; } return(RedirectToAction("Success", "Cart")); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var order = new Order(); // Tạo 1 đơn hàng order.CreateDate = DateTime.Now; order.ShipName = shipName; order.ShipMobile = mobile; order.ShipAddress = address; order.ShipEmail = email; try { var id = new OrderDAO().Insert(order); // Thêm mới 1 đơn hàng var cartSession = (List <CartItem>)Session[Common.SessionCommonConstants.CART_SESSION]; // Lấy danh sách giỏ hàng từ Session var detailDAO = new OrderDetailDAO(); decimal?total = 0; foreach (var item in cartSession) { var detail = new OrderDetail(); detail.ProductID = item.Product.ID; detail.OrderID = id; detail.Quantity = item.Quantity; detail.Price = (item.Product.PromotionPrice != null ? item.Product.PromotionPrice : item.Product.Price); detailDAO.Insert(detail); // Thêm từng sản phẩm trong đơn hàng total += (detail.Price * detail.Quantity); // Tính tổng tiền } // Đọc file nội dung Email string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/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.GetValueOrDefault(0).ToString("N0")); // Địa chỉ Email quản trị var toEmailAddress = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); // Gửi Email new EmailHelper().SendEmail(email, "Đơn Hàng Mới Từ OnlineShop", content); // Gửi Email cho khách mua hàng new EmailHelper().SendEmail(toEmailAddress, "Đơn Hàng Mới Từ OnlineShop", content); // Gửi Email cho quản trị } catch (Exception ex) { return(Redirect("/loi-thanh-toan")); } return(Redirect("/hoan-thanh")); }
public ActionResult Payment(string txtShipName, string txtAddress, string txtPhone, string txtEmail) { var order = new Order(); order.CreateDate = DateTime.Now; order.ShipAddress = txtAddress; order.ShipPhone = txtPhone; order.ShipName = txtShipName; order.ShipEmail = txtEmail; var id = new OrderDAO().Insert(order); try { var cart = (List <CartItem>)Session[CartSession]; var orderDetailDAO = new OrderDetailDAO(); decimal total = 0; int quantity = 0; foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.Product.IDProduct; orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.Quantity = item.Quantity; orderDetailDAO.Insert(orderDetail); total += (item.Product.Price * item.Quantity); quantity = item.Quantity; } // khởi tạo 1 biến content để đọc html rồi gán thành string string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/orderclient.html")); content = content.Replace("{{IdOrder}}", id.ToString()); content = content.Replace("{{CustomerName}}", txtShipName); content = content.Replace("{{Address}}", txtAddress); content = content.Replace("{{Phone}}", txtPhone); content = content.Replace("{{Email}}", txtEmail); content = content.Replace("{{Total}}", total.ToString("N0")); var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); new MailHelper().SendMail(txtEmail, "Đơn hàng từ Shop", content); //new MailHelper().SendMail(toEmail, "Đơn hàng từ Shop", content); } catch (Exception e) { throw; } return(Redirect("/hoan-thanh")); }
public ActionResult PaymentUserLogin() { var username = Session["UsernameMember"];//lấy session gáng giá trị vào order var model = new UserDAO().findByUsername(username.ToString()); var order = new Order(); order.ShipCreateDate = DateTime.Now; order.ShipName = model.Name; order.ShipAddress = model.Address; order.ShipEmail = model.Email; order.ShipPhone = model.Phone; order.Status = 0; order.PaymentID = 2; order.UserID = model.ID; //insert order var id = new OrderDAO().Create(order);//trả về id của order try { var cart = (List <CartItem>)Session[CartSession]; var db = new OrderDetailDAO(); foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.ProductModel.ID; orderDetail.OrderID = id; if (item.ProductModel.Sale != null) { orderDetail.Price = item.ProductModel.Sale; } else { orderDetail.Price = item.ProductModel.Price; } orderDetail.Quantity = item.Quantity; db.Create(orderDetail); Session[CartSession] = null; } EmailTool emailTool = new EmailTool(); emailTool.SendMail(GetParent(id)); } catch (Exception) { throw; } return(RedirectToAction("Success", "Cart")); }
public JsonResult Add(string orderDetail, List <ProductCartViewModel> listProduct, int totalCost) { JavaScriptSerializer serializer = new JavaScriptSerializer(); var OrderDetail = serializer.Deserialize <OrderDetail>(orderDetail); var OrderID = new OrderDAO().insert(listProduct, totalCost); var status = new OrderDetailDAO().insert(OrderDetail, OrderID); return(Json(new { status = status, id = OrderID })); }
public ActionResult Payment(string shipName, string shipPhone, string shipAddress, string shipEmail) { var order = new Order(); order.ShipCreateDate = DateTime.Now; order.ShipName = shipName; order.ShipAddress = shipAddress; order.ShipEmail = shipEmail; order.ShipPhone = shipPhone; order.Status = 0; order.PaymentID = 2; //insert order var id = new OrderDAO().Create(order);//trả về id của order try { var cart = (List <CartItem>)Session[CartSession]; var db = new OrderDetailDAO(); foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.ProductModel.ID; orderDetail.OrderID = id; if (item.ProductModel.Sale != null) { orderDetail.Price = item.ProductModel.Sale; } else { orderDetail.Price = item.ProductModel.Price; } orderDetail.Quantity = item.Quantity; db.Create(orderDetail); Session[CartSession] = null; } EmailTool emailTool = new EmailTool(); emailTool.SendMail(GetParent(id)); } catch (Exception) { throw; } return(RedirectToAction("Success", "Cart")); }
private void btnTaoHoaDon_Click(object sender, EventArgs e) { try { OrderDAO dt = new OrderDAO(); OrderDetailDAO dc = new OrderDetailDAO(); Order a = new Order(); a.OrderName = txtTenHoaDon.Text; a.TotalPrice = decimal.Parse(txtTongTien.Text); a.Date = DateTime.Today; a.EmployeeID = LoginDetail.LoginID; a.Status = false; int b = dt.Insert(a); if (b != 0) { for (int i = 0; i < grChiTiet.RowCount; i++) { OrderDetail c = new OrderDetail(); c.OrderID = b; c.IngredientID = (int)grChiTiet.GetRowCellValue(i, grChiTiet.Columns["IngredientID"]); c.PriceOfUnit = (decimal)grChiTiet.GetRowCellValue(i, grChiTiet.Columns["PriceOfUnit"]); c.QuantityOfUnit = (int)grChiTiet.GetRowCellValue(i, "QuantityOfUnit"); c.TotalPrice = (decimal)grChiTiet.GetRowCellValue(i, "TotalPrice"); c.Status = false; if (dc.Insert(c) == true) { } else { MessageBox.Show("Bản ghi thứ " + i + " không được lưu lại"); break; } } MessageBox.Show("Lưu thành công"); OrderDetailDAO.ThanhToan = true; this.Close(); // in hóa đơn } else { MessageBox.Show("Khởi tạo thất bại"); } } catch { } }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var order = new Order(); order.CreateDate = 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[CommonConstant.CartSession]; var detailDao = new OrderDetailDAO(); decimal total = 0; foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.Product.ID; orderDetail.OderID = 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("~/assets/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(toEmail, "Đơn hàng mới từ OnlineShop", content); //new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop", content); } catch { //ghi log return(Redirect("/loi-thanh-toan")); } return(Redirect("/hoan-thanh")); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { var order = new OrderBy(); order.CreatedDate = DateTime.Now; order.ShipName = shipName; order.ShipMobile = mobile; order.ShipEmail = email; order.ShipAddress = address; try { decimal total = 0; var id = new OrderByDAO().Insert(order); var cart = (List <CartChild>)Session[CommonConstants.CART_SESSION]; var detailDAO = new OrderDetailDAO(); 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; orderdetail.Status = true; detailDAO.Insert(orderdetail); total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity); } string content = System.IO.File.ReadAllText(Server.MapPath("/Assets/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}}", string.Format("{0:C}", (total)).Replace(",00", "")); new MailHelper().SendMail("Đơn hàng từ AppleStore", content); } catch (Exception) { throw; } return(RedirectToAction("Success", "Cart")); }
public ActionResult ShowDetailBill() { if (Regex.IsMatch(Request["OrderID"], "^\\d+$")) { int id = int.Parse(Request["OrderID"]); id -= 491999; OrderDetailDAO dao = new OrderDetailDAO(); List <OrderDetailDTO> listOrderDetail = dao.GetBillDetail(id); BillDAO daoBill = new BillDAO(); float discount = daoBill.GetDiscount(id); string state = daoBill.GetState(id); ViewBag.Discount = discount; ViewBag.State = state; ViewBag.ListOrderDetail = listOrderDetail; } return(View("ViewDetailBill")); }
public ActionResult ThongTinDonHang() { var session = (Common.LoginDetail)Session[Common.CommonConstants.USER_SESSION]; var productdao = new ProductDAO(); ViewBag.XemNhieuNhat = productdao.XemNhieuNhat(); var orderdao = new OrderDAO(); var vieworder = orderdao.ViewOrderByCustomerID(session.User.ID); ViewBag.ViewOrder = vieworder; var orderdetaildao = new OrderDetailDAO(); var list = orderdetaildao.List(vieworder.ID); return(View(list)); }