public ActionResult Checkout(string receiver, string phone, string address) { User user = (User)Session["USER"]; if (user != null) { CartObj cart = (CartObj)Session["CART"]; if (cart != null) { DateTime date = DateTime.Now; OrderDAO daoOrder = new OrderDAO(); OrderDetailsDAO daoDetails = new OrderDetailsDAO(); Order order = new Order() { phone = phone, receiver = receiver, addressShip = address, username = user.username, orderDate= date}; daoOrder.Add(order); int currentID = daoOrder.GetCurrentOrderID(); foreach(var item in cart.cart) { OrderDetail details = new OrderDetail() { orderID = currentID, phoneID = item.Key.phoneID, price = item.Key.price, quantity = item.Value, discount = item.Key.discount }; daoDetails.Add(details); PhoneDAO daoPhone = new PhoneDAO(); daoPhone.UpdateQuantity(item.Value,item.Key.phoneID); } Session["CART"] = null; } } return RedirectToAction("Index", "Home", new { area = "" }); }
public ActionResult Payment(string ShipName, string mobile, string address, string email) { //lấy thông tin truyền vào order var order = new Order(); order.CreatedDate = DateTime.Now; order.ShipAddress = address; order.ShipMobile = mobile; order.ShipEmail = email; order.ShipName = ShipName; try { //lấy thông tin var id = new OrderDAO().Insert(order); //lấy ad sản phẩm var cart = (List <CartItem>)Session[CartSession]; //lấy ra thông tin sản phẩm var detailDao = new OrderDetailsDAO(); decimal total = 0; foreach (var item in cart) { //insert vào OrderDetail 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); //tổng tiền } string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html")); //định đạng thành đối tượng content = content.Replace("{{CustomerName}}", ShipName); //lấy giá trị CustomerName từ file neworder.html content = content.Replace("{{Phone}}", mobile); content = content.Replace("{{Email}}", email); content = content.Replace("{{Address}}", address); content = content.Replace("{{Total}}", total.ToString("N0")); //ToString("N0"): chuyển đổi giá trị sang VN var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); //mail quản trị //Gửi mail thông báo cho người dùng và quản trị có đơn hàng mới new MailHelp().SendMail(email, "Đơn hàng mới từ GROCERY STORE", content); //gửi tới mail khách hàng new MailHelp().SendMail(toEmail, "Đơn hàng mới từ GROCERY STORE", content); //mail này trả ngược về mail admin } catch (Exception ex) { //ghi log return(Redirect("/loi-thanh-toan")); } return(Redirect("/hoan-thanh")); }
public ActionResult Payment(string shipName, string mobile, string address, string email) { ViewBag.Title = "Trang Thanh Toán | Buy And Sell Cars"; var order = new Order(); order.CreatedDate = DateTime.Now; var user = (UserLogin)Session[Common.LoginClientConstant.CLIENT_SESSION]; if (user != null) { order.CustomerID = user.UserID; } else { order.CustomerID = 0; } order.ShipName = shipName; order.ShipMobile = mobile; order.ShipAddress = address; order.ShipEmail = email; order.Status = 1; try { long orderID = new OrderDAO().InsertOrder(order); var sessionCart = (List <CartItem>)Session[CartSession]; foreach (var item in sessionCart) { var orderdetail = new OrderDetail(); orderdetail.OrderID = orderID; orderdetail.ProductID = item.CarPart.ID; orderdetail.Price = item.CarPart.PromotionPrice != -1 ? item.CarPart.PromotionPrice : item.CarPart.Price; orderdetail.Quantity = item.Quantity; var res = new OrderDetailsDAO().InsertDetails(orderdetail, orderID); } } catch (Exception) { // return(Redirect("/loi-thanh-toan")); } Session[CartSession] = null; return(Redirect("/hoan-thanh")); }
public static OrderDetail GetOrderDetail(int ID) { return(OrderDetailsDAO.GetOrderDetail(ID)); }
public static List <OrderDetail> GetOrderDetails() { return(OrderDetailsDAO.GetOrderDetails()); }
public static int DeleteOrderDetail(int ID) { return(OrderDetailsDAO.DeleteOrderDetail(ID)); }
public static int UpdateOrderDetaiL(OrderDetail orderDetail) { return(OrderDetailsDAO.UpdateOrderDetail(orderDetail)); }
public static int InsertOrderDetails(OrderDetail orderDetail) { return(OrderDetailsDAO.InsertOrderDetails(orderDetail)); }