예제 #1
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new HOADON();

            order.Ngay      = DateTime.Now;
            order.DiaChi    = address;
            order.DienThoai = mobile;
            order.TenKH     = shipName;
            order.email     = email;

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new HOADON_CHITIET();
                    orderDetail.IdSP     = item.SanPham.ID;
                    orderDetail.MaHD     = id;
                    orderDetail.TongTien = item.SanPham.Gia;
                    orderDetail.SoLuong  = item.SoLuong;
                    detailDao.Insert(orderDetail);

                    total += (item.SanPham.Gia.GetValueOrDefault(0) * item.SoLuong);
                }
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #2
0
        public JsonResult AddRow(string row)
        {
            var         json        = new JavaScriptSerializer().Deserialize <OrderDetail>(row);
            OrderDetail orderDetail = new OrderDetail();

            orderDetail.OrderID   = json.OrderID;
            orderDetail.ProductID = json.ProductID;
            orderDetail.Price     = json.Price;
            orderDetail.Quantity  = json.Quantity;
            var dao = new OrderDetailDao();

            if (dao.CheckExistRow(orderDetail.OrderID, orderDetail.ProductID) == false)
            {
                dao.Insert(orderDetail);
                return(Json(new
                {
                    status = true
                }));
            }
            else
            {
                return(Json(new
                {
                    status = false
                }));
            }
        }
예제 #3
0
        public JsonResult Payment(string email, string name, string province, string district, string ward, string address, string phone)
        {
            var order = new Order();

            order.ShipName   = name;
            order.ShipMobile = phone;
            order.ShipAdress = address + "-" + ward + "-" + district + "-" + province;
            order.ShipEmail  = email;

            try
            {
                var id          = new OrderDao().Insert(order);
                var cart        = (List <CartItem>)Session[CommonConst.CartSession];
                var orderdetail = new OrderDetailDao();
                foreach (var item in cart)
                {
                    var detail = new OrderDetail();
                    detail.OrderID   = id;
                    detail.ProductID = item.Product.ID;
                    detail.Price     = item.Product.Price;
                    detail.Quantity  = item.Quantity;
                    orderdetail.Insert(detail);
                }
            }
            catch
            {
            }
            return(Json(new
            {
                status = true
            }));
            // return RedirectToAction("Index", "Home");
        }
예제 #4
0
        public ActionResult Payment(string ShipName, string ShipMobile, string ShipAddress, string ShipEmail)
        {
            var order = new Order();

            order.CreateDate  = DateTime.Now;
            order.ShipAddress = ShipAddress;
            order.ShipName    = ShipName;
            order.ShipEmail   = ShipEmail;
            order.ShipMobile  = ShipMobile;
            //add 1 order va lay ra ID de add product vao orderdetail
            long id = new OrderDao().Insert(order);
            var  listOrderDetail = (List <CartItem>)Session[CartSession];
            var  orderdetaildao  = new OrderDetailDao();

            foreach (var item in listOrderDetail)
            {
                var OrderDetail = new OrderDetail();
                OrderDetail.OrderID     = id;
                OrderDetail.ProductID   = item.Product.ID;
                OrderDetail.Quantity    = item.Quantity;
                OrderDetail.Price       = item.Product.Price;
                OrderDetail.ProductName = item.Product.Name;
                orderdetaildao.Insert(OrderDetail);
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #5
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.CustomerID  = null;
            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItem>)Session[CartSession];
                var detailDao = new OrderDetailDao();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ProductID;
                    orderDetail.OrderID   = id;
                    orderDetail.Price     = item.Product.Price;
                    orderDetail.Quantity  = item.Quantity;
                    detailDao.Insert(orderDetail);
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return(Redirect("/Cart/Success"));
        }
예제 #6
0
        public ActionResult Payment(string shipName, string phone, string address, string email)
        {
            try
            {
                var order = new Order()
                {
                    CreateDate  = DateTime.Now,
                    ShipName    = shipName,
                    ShipEmail   = email,
                    ShipAddress = address,
                    ShipMobile  = phone
                };
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItem>)Session[CommonConstants.CartSession];
                var detailDao = new OrderDetailDao();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail()
                    {
                        OrderID   = id,
                        ProductID = item.Product.ID,
                        Price     = item.Product.Price,
                        Quanlity  = item.Quanlity
                    };
                    detailDao.Insert(orderDetail);
                }
            }
            catch
            {
                throw;
            }

            return(Redirect("/hoan-thanh"));
        }
        public ActionResult ThanhToan(string nguoinhan, string dienthoai, string diachi, string email)
        {
            var order = new Order();

            order.NgayTao   = DateTime.Now;
            order.TenKH     = nguoinhan;
            order.DiaChi    = diachi;
            order.DienThoai = dienthoai;
            order.Email     = email;
            order.TrangThai = false;

            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <GioHang>)Session["GioHang"];
                var detailDao = new OrderDetailDao();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.IDProduct = item.iMaSP;
                    orderDetail.IDOrder   = id;
                    orderDetail.Price     = item.ThanhTien;
                    orderDetail.Quantity  = item.iSoLuong;
                    detailDao.Insert(orderDetail);
                    Session["GioHang"] = null;
                }
            }
            catch (Exception ex)
            {
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #8
0
        public ActionResult Payment(string name, string number, string address, string email)
        {
            var order = new Order();

            order.CreateDate  = DateTime.Now;
            order.ShipAddress = address;
            order.ShipName    = name;
            order.ShipMobile  = number;
            order.ShipEmail   = email;

            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItem>)Session[CartSession];
                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;
                    detailDao.Insert(orderDetail);
                }
            }
            catch (Exception ex)
            {
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #9
0
        public ActionResult Payment(string name, string address, string mobile, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipName    = name;
            order.ShipAddress = address;
            order.ShipMobile  = mobile;
            order.ShipEmail   = email;
            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItem>)Session[CommonConstants.CartSession];
                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.ProductName     = item.Product.Name;
                    orderDetail.SubTotalProduct = (item.Quantity) * (item.Product.Price);

                    detailDao.Insert(orderDetail);
                }
            }
            catch (Exception)
            {
                return(Redirect("/erro-payment"));
            }
            return(Redirect("/success"));
        }
        public ActionResult SaveOrderPay(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            var userSession = (UserLogin)Session[OnlineShop.Common.CommonConstants.USER_SESSION];

            order.CustomerID  = userSession.UserID;
            order.ShipName    = shipName;
            order.ShipMobile  = mobile;
            order.ShipAddress = address;
            order.ShipEmail   = email;

            var id        = new OrderDao().Insert(order);
            var cart      = (List <CartItem>)Session[CommonConstants.CartSession];
            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;
                detailDao.Insert(orderDetail);
            }
            return(Json(new
            {
                status = true
            }));
        }
예제 #11
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            MyDB db    = new MyDB();
            var  order = new Order();

            order.ShipName    = shipName;
            order.ShipMobile  = mobile;
            order.ShipAddress = address;
            order.ShipEmail   = email;
            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSesion];
                var     detailDao = new OrderDetailDao();
                var     qtt       = new ProductDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.product.ID;
                    orderDetail.OrderID   = id;

                    if (item.product.PromotionPrice == null)
                    {
                        total             = (item.product.Price.GetValueOrDefault(0) * item.Quantity);
                        orderDetail.Price = total;
                    }
                    else
                    {
                        total             = (item.product.PromotionPrice.GetValueOrDefault(0) * item.Quantity);
                        orderDetail.Price = total;
                    }
                    orderDetail.Quantity = item.Quantity;
                    detailDao.Insert(orderDetail);
                    var quantityProduct = new Product();
                    quantityProduct.ID = item.product.ID;
                    var mode = db.Products.Find(quantityProduct.ID);

                    mode.Quantity = (item.product.Quantity - item.Quantity);
                    db.SaveChanges();
                }

                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}}", email);
                //content = content.Replace("{{Total}}", total.ToString("N0"));
                //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                // new MailHelper().SenMail(email, "Đơn hàng mới từ OnlineShop", content);
                // new MailHelper().SenMail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            catch
            {
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #12
0
        public ActionResult payment(string shipName, string mobile, string address, string email)
        {
            var order = new DonDatHang();

            order.NgayDat        = DateTime.Now;
            order.DiaChiGiaoHang = address;
            order.SoDienThoai    = mobile;
            order.TenNguoiDat    = shipName;
            order.Email          = email;
            order.TrangThai      = 1;

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CommonConstants.CART_SEDSSION];
                var     detailDao = new OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new ChiTietDatHang();
                    orderDetail.MaDon = id;
                    orderDetail.MaSP  = item.Product.MaSP;

                    if (item.Product.GiaKhuyenMai != null)
                    {
                        orderDetail.DonGia = item.Product.GiaKhuyenMai;
                    }
                    else
                    {
                        orderDetail.DonGia = item.Product.DonGia;
                    }

                    orderDetail.SoLuong = item.Quantity;
                    detailDao.Insert(orderDetail);

                    //total += (item.Product.DonGia.GetValueOrDefault(0) * item.Quantity);
                }
                Session[CommonConstants.CART_SEDSSION] = null;
                //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(email, "Đơn hàng mới từ Shop", content);
                //new MailHelper().SendMail(toEmail, "Đơn hàng mới từ Shop", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #13
0
        public ActionResult Payment(string shipName, string phone, string address, string email, string note)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipName    = shipName;
            order.ShipEmail   = email;
            order.ShipMobile  = phone;
            order.ShipAddress = address;
            order.Note        = note;
            order.Status      = 1;
            try
            {
                var cart = (List <CartItem>)Session[Common.CommonConstants.CartSession];

                if (cart == null || cart.Count < 1)
                {
                    return(Redirect("/hoan-thanh"));
                }
                var id = new OrderDao().Insert(order);
                TempData["ID"] = id;
                var detailDao = new OrderDetailDao();

                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    if (item.Product.PromotionPrice == 0)
                    {
                        orderDetail.Price = item.Product.Price;
                    }
                    else
                    {
                        orderDetail.Price = item.Product.PromotionPrice;
                    }

                    orderDetail.Quantity = item.Quantity;
                    detailDao.Insert(orderDetail);

                    var dao = new ProductDao();
                    item.Product.Quantity -= item.Quantity;
                    var product = item.Product;
                    dao.ChangeQuantity(product);
                }
            }
            catch (Exception ex)
            {
                throw;
            }


            return(Redirect("/hoan-thanh"));
        }
예제 #14
0
        public JsonResult CreateOrder(string orderViewModel)
        {
            var order    = new JavaScriptSerializer().Deserialize <OrderViewModel>(orderViewModel);
            var orderDao = new OrderDao();
            var orderNew = new Order();

            orderNew.CreatedDate     = DateTime.Now;
            orderNew.CustomerAddress = order.CustomerAddress;
            orderNew.CustomerMobile  = order.CustomerMobile;
            orderNew.CustomerName    = order.CustomerName;
            orderNew.CustomerEmail   = 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 <ShoppingCartViewModel>)Session[CommonConstants.SessionCart];
            decimal total       = 0;

            foreach (var item in sessionCart)
            {
                var detail = new OrderDetail();
                detail.OrderID   = orderNew.ID;
                detail.ProductID = item.ProductId;
                detail.Quantitty = 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 * item.Quantity);
                }
                detailDao.Insert(detail);
            }

            string content = System.IO.File.ReadAllText(Server.MapPath("~/Assets/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"));
            MailHelper.SendMail(order.CustomerEmail, "Thông tin đơn đặt hàng từ BookStore", content);
            Session[CommonConstants.SessionCart] = null;
            return(Json(new
            {
                status = true
            }));
        }
예제 #15
0
        public ActionResult Payment(string shipName, string mobile, string address)
        {
            decimal total = 0;
            var     user  = ((UserLoginSession)Session[ConstantSession.USER_CLIENT_SESSION]);
            var     order = new Order();

            order.CreateDate  = DateTime.Now;
            order.UserID      = user.UserID;
            order.ShipAddress = address;
            order.ShipName    = shipName;
            order.ShipMobile  = mobile;
            order.ShipEmail   = user.Email;
            order.Status      = 1;
            try
            {
                var id        = new OrderDao().Insert(order);
                var cart      = (List <CartItemViewModel>)Session[CartSession];
                var detailDao = new OrderDetailDao();
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();

                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;
                    var price = item.Product.PromotionPrice.GetValueOrDefault(0) > 0 ? item.Product.PromotionPrice : item.Product.Price;
                    orderDetail.Price    = price.Value;
                    orderDetail.Quantity = item.Quantity;
                    detailDao.Insert(orderDetail);

                    total += (price.Value * item.Quantity);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/Asset/Client/template/neworder.html"));
                content = content.Replace("{{CustomerName}}", shipName);
                content = content.Replace("{{Phone}}", mobile);
                content = content.Replace("{{Email}}", user.Email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Total}}", total.ToString("N0"));

                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                new MailHelper().SendMail(user.Email, "Đơn hàng mới", content);//gui mail khach hang
                //new MailHelper().SendMail(toEmail, "Đơn hàng mới", content);//gui mail cho quan tri vien
            }
            catch (Exception)
            {
                //ghi log
                //return Redirect("/trang-loi");
                throw;
            }
            Session[CartSession] = null;
            return(Redirect("/hoan-thanh"));
        }
예제 #16
0
        public ActionResult Payment()
        {
            var cart = (List <CartItem>)Session[Constant.CartSession];

            if (cart != null)
            {
                var orderDao = new OrderDao();
                var order    = new Order();
                var user     = (Model.EF.User)Session[Constant.USER_SESSION];

                order.IDCustomer  = user.ID;
                order.ShipName    = user.Name;
                order.ShipPhone   = user.Phone;
                order.ShipAddress = user.Address;
                order.Status      = false;
                order.CreatedDate = DateTime.Now;
                long orderId = orderDao.Insert(order);
                if (orderId != -1)
                {
                    foreach (var item in cart)
                    {
                        var     orderDetailDao = new OrderDetailDao();
                        var     orderDetail    = new OrderDetail();
                        decimal price          = item.product.PromotionPrice != null ? item.product.PromotionPrice : item.product.Price;

                        orderDetail.ProductID = item.product.ID;
                        orderDetail.OrderID   = orderId;
                        orderDetail.Price     = price;
                        orderDetail.Quantity  = item.Quantity;
                        if (orderDetailDao.Insert(orderDetail) != true)
                        {
                            TempData["ErrPay"] = "";
                            return(Redirect("/gio-hang"));
                        }
                    }
                }
                else
                {
                    TempData["ErrPay"] = "";
                    return(Redirect("/gio-hang"));
                }
                Session[Constant.CartSession] = null;
                TempData["PayOke"]            = "";
                return(Redirect("/"));
            }
            else
            {
                TempData["NullCart"] = "";
                return(Redirect("/gio-hang"));
            }
        }
예제 #17
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order
            {
                CreatedDate = DateTime.Now,
                ShipName    = shipName,
                ShipAddress = address,
                ShipMobile  = mobile,
                ShipEmail   = email
            };

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[Common.CommonConstants.CartSession];
                var     detailDao = new OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail
                    {
                        ProductID = item.Product.ID,
                        OrderID   = id,
                        Price     = item.Product.Price,
                        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().SendEmail(email, "Đơn hàng mới từ OnlineShop", content);
                new MailHelper().SendEmail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            catch (Exception)
            {
                // logs
                return(Redirect("/loi-thanh-toan"));
            }

            return(Redirect("/hoan-thanh"));
        }
예제 #18
0
        public ActionResult Payment(string shipname, string mobile, string address, string email)
        {
            var order = new Order();

            order.CratedDate  = DateTime.Now;
            order.ShipAddress = address;
            order.ShipMobile  = mobile;
            order.ShipEmail   = email;
            order.ShipName    = shipname;
            Product pro = new Product();

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <Caritem>)Session[CartSession];
                var     detaildao = new OrderDetailDao();
                decimal total     = 0;
                string  sp        = "";
                foreach (var item in cart)
                {
                    var orderdetail = new OrderDetail();
                    orderdetail.ProductID = item.Product.ID;
                    orderdetail.OrderID   = id;
                    orderdetail.Price     = item.Product.Price;
                    orderdetail.Quantily  = item.Quantily;
                    detaildao.Insert(orderdetail);
                    sp     = string.Concat(sp, item.Product.Name);
                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantily);
                    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("{{Name}}", sp);

                    content = content.Replace("{{Total}}", total.ToString("N0"));
                    var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                    new MailHelper().SendMail(email, "Đơn hàng mới từ ShopOnline", content);
                    new MailHelper().SendMail(toEmail, "Đơn hàng mới từ ShopOnline", content);
                }
            }
            catch (Exception)
            {
                // ghi long
                return(Redirect("/loi-hoan-thanh"));
            }

            return(Redirect("/hoan-thanh"));
        }
예제 #19
0
        public ActionResult PaymentUser()
        {
            var session = (UserLogin)Session[CommonConstants.USER_SESSION];
            var order   = new Order();

            order.ShipName    = session.Name;
            order.ShipMobile  = session.Phone;
            order.ShipEmail   = session.Email;
            order.ShipAddress = session.Address;
            order.CustomerID  = session.UserId;
            order.CreatedDate = DateTime.Now;
            try
            {
                var id   = new OrderDao().Insert(order);
                var cart = (List <CartItem>)Session[CartSession];

                var     detailDao = new 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("~/Asset/client/template/newOrder.html"));

                content = content.Replace("{{CustomerName}}", session.UserName);
                content = content.Replace("{{Phone}}", session.Phone);
                content = content.Replace("{{Email}}", session.Email);
                content = content.Replace("{{Address}}", session.Address);
                content = content.Replace("{{Total}}", total.ToString("N0"));
                //content=content.Replace("{{Name}}",)
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(session.Email, "Đơn hàng mới từ Luxury Watch", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ Luxury Watch", content);

                Session[CartSession] = null;
            }
            catch
            {
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #20
0
        public ActionResult Payment(string name, string address, string phone, string email)
        {
            var    session = (UserLogin)Session[OnlineShop.Common.CommonConstant.USER_SESSION];
            var    order   = new Order();
            string code    = CodeChangePass(6);

            if (session != null)
            {
                order.CreatedDate = DateTime.Now;
                order.ShipAddress = address;
                order.ShipEmail   = email;
                order.ShipMobile  = phone;
                order.ShipName    = name;
                order.CustomerID  = session.UserID;
                order.Status      = 1;
                order.Code        = code;
            }
            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderdetail = new OrderDetail();
                    orderdetail.ProductID = item.Product.ID;
                    orderdetail.OrderID   = id;
                    orderdetail.Size      = item.Size;
                    orderdetail.Quantity  = item.Quantity;
                    orderdetail.Price     = item.Product.Price;
                    detailDao.Insert(orderdetail);
                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("/assets/net/template/neworder.html"));
                content = content.Replace("{{CustomerName}}", name);
                content = content.Replace("{{Phone}}", phone);
                content = content.Replace("{{Email}}", email);
                content = content.Replace("{{Address}}", address);
                content = content.Replace("{{Code}}", code);
                content = content.Replace("{{Total}}", total.ToString());
                new MailHelper().SendEmail(email, "Xác nhận đơn hàng", content);
            }
            catch (Exception)
            {
                throw;
            }
            Session[CartSession] = null;
            return(Redirect("/hoan-thanh"));
        }
예제 #21
0
        public ActionResult Payment(long matk, int tongtien, string nguoidat, string nguoinhan, string diachi, string sdt)
        {
            var order = new DonHang();

            order.NgayDatHang     = DateTime.Now;
            order.NguoiDat        = nguoidat;
            order.NguoiNhan       = nguoinhan;
            order.DiaChiNguoiNhan = diachi;
            order.SDTNguoiNhan    = sdt;
            order.TrangThai       = 1;
            order.MaTK            = matk;
            order.TongTien        = tongtien;
            var dataDate = DateTime.Now.ToString();

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     product   = new ProductDao();
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new OrderDetailDao();
                decimal total     = tongtien;
                foreach (var item in cart)
                {
                    var orderDetail = new ChiTietDH();
                    orderDetail.MaSach  = item.Sach.MaSach;
                    orderDetail.MaDH    = id;
                    orderDetail.TenSP   = item.Sach.TenSach;
                    orderDetail.DonGia  = item.Sach.GiaBan;
                    orderDetail.SoLuong = item.SoLuong;
                    detailDao.Insert(orderDetail);
                    Sach book = product.ViewDetail(item.Sach.MaSach);
                    product.UpdateQuantity(book, item.SoLuong);
                }
                string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/template/order.html"));

                content = content.Replace("{{CustomerName}}", nguoidat);
                content = content.Replace("{{Phone}}", sdt);
                content = content.Replace("{{Date}}", dataDate);
                content = content.Replace("{{Address}}", diachi);
                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);
            }
            catch (Exception)
            {
                //return Redirect("/loi-thanh-toan");
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #22
0
        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;

            var id        = new OrderDao().Insert(order);
            var cart      = (List <CartItem>)Session[CartSession];
            var detailDao = new OrderDetailDao();

            decimal total = 0;

            try
            {
                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.Product.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"));
                // toEmail cho quản trị
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                // gửi back up cho dray
                new MailHelper().SendMail(email, "Đơn hàng mới từ OnlineShop dành cho khách hàng", content);
                // gửi cho người gửi
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop dành cho shop quản trị được setting in webconfig", content);
            }
            catch (Exception)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #23
0
        public ActionResult Payment(string shipName, long?CusID, string mobile, string address, string email)
        {
            var order = new Order();

            order.CustomerID  = CusID;
            order.CreatedDate = 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 OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.ProductID = item.Product.ID;
                    orderDetail.OrderID   = id;

                    orderDetail.Quantity = item.Quantity;



                    total            += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                    orderDetail.Price = total;
                    detailDao.Insert(orderDetail);
                }
                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"));
                //string toEmail = email;


                new MailHelper().SendEmail(email, "Đơn hàng mới từ MocCoffee", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #24
0
        public ActionResult Pay(string shipName, string shipMobile, string shipAddress, string shipEmail)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipName    = shipName;
            order.ShipMobile  = shipMobile;
            order.ShipAddress = shipAddress;
            order.ShipEmail   = shipEmail;
            order.Status      = 2;
            try
            {
                var dao = new OrderDao();
                var id  = dao.Insert(order);
                order.DocNo = dao.UpdateDocNo("OR", id);
                var     cart      = (List <CartItem>)Session[CartSession];
                var     detailDao = new 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("/Assets/Client/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.ToString("N0"));
                var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                new MailHelper().SendMail(shipEmail, "New order from BatmanShop", content);
                new MailHelper().SendMail(toEmail, "New order from BatmanShop", content);
            }
            catch (Exception ex)
            {
                return(Redirect("/Unsuccessful"));
            }

            return(Redirect("/Successful"));
        }
예제 #25
0
        public ActionResult Payment(string shipname, string mobile, string address, string email)
        {
            var session = (userLogin)Session[CommonConstants.USER_SESSION];
            var order   = new Order();

            if (session == null)
            {
                order.NgayTao   = DateTime.Now;
                order.DiaChi    = address;
                order.SDT       = mobile;
                order.Email     = email;
                order.NguoiNhan = shipname;
            }
            else
            {
                order.MaUser    = session.UserID;
                order.NgayTao   = DateTime.Now;
                order.DiaChi    = address;
                order.SDT       = mobile;
                order.Email     = email;
                order.NguoiNhan = shipname;
            }
            try
            {
                var     id            = new OrderDao().Insert(order);
                var     cart          = (List <CartItem>)Session[CartSession];
                var     detailDao     = new OrderDetailDao();
                decimal TongThanhToan = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.MaSP      = item.Product.ID;
                    orderDetail.MaGioHang = id;
                    orderDetail.DonGia    = item.Product.GiaBan;
                    orderDetail.SoLuong   = item.SoLuong;
                    detailDao.Insert(orderDetail);
                    TongThanhToan += (item.Product.GiaBan.GetValueOrDefault(0) * item.SoLuong);
                }
                order.ThanhTien = TongThanhToan;
                new OrderDao().Update(order);
            }
            catch (Exception ex)
            {
                return(Redirect("/"));
            }
            return(Redirect("/hoan-thanh"));
        }
예제 #26
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = DateTime.Now;
            order.ShipAddress = address;
            order.ShipName    = shipName;
            order.ShipMobile  = mobile;
            order.ShipEmail   = email;


            try {
                var     id             = new OrderDao().Insert(order);
                var     cart           = (List <CartItem>)Session[CartSession];
                var     orderDetailDao = new OrderDetailDao();
                decimal totalPrice     = 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;
                    orderDetailDao.Insert(orderDetail);

                    totalPrice += (item.Product.Price.GetValueOrDefault(0) * item.Quantity);
                    //Session.Remove("CartSession");
                }
                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}}", totalPrice.ToString("N0"));

                var toEmail    = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();
                var mailHelper = new MailHelper();
                mailHelper.SendMail(email, "Đơn hàng mới từ OnlineShop", content);
                new MailHelper().SendMail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            catch (Exception ex)
            {
            }

            return(Redirect("/finish-payment"));
        }
예제 #27
0
 public ActionResult Create(OrderDetail orderDetail)
 {
     if (ModelState.IsValid)
     {
         var  dao = new OrderDetailDao();
         long id  = dao.Insert(orderDetail);
         if (id > 0)
         {
             return(RedirectToAction("Index", "OrderDetail"));
         }
         else
         {
             ModelState.AddModelError("", "Add Order Detail successfully");
         }
     }
     return(View("Index"));
 }
예제 #28
0
        public ActionResult Payment(string note)
        {
            //var id = new OrderDao().Insert(order);
            try
            {
                UserDao user   = new UserDao();
                long    iduser = user.getIdUser();
                User    user1  = user.ViewDetail(iduser);
                DonHang order  = new DonHang();
                order.IdUser       = iduser;
                order.NgayTao      = DateTime.Now;
                order.DiaChiNhan   = user1.DiaChi;
                order.SDTNguoiNhan = user1.DienThoai;
                order.TenNguoiNhan = user1.HoTen;
                order.Email        = user1.Email;
                order.GhiChu       = note;
                order.TongTien     = 0;
                order.TrangThai    = "Chưa xác nhận";

                OrderDao od = new OrderDao();
                var      id = od.Insert(order);

                var cart = (List <CartItem>)Session[CartSession];

                foreach (var item in cart)
                {
                    OrderDetailDao detailDao   = new OrderDetailDao();
                    var            orderDetail = new ChiTietDonHang();
                    orderDetail.MaSach    = item.Product.MaSach;
                    orderDetail.DonGia    = item.Product.DonGia;
                    orderDetail.SoLuong   = item.Quantity;
                    orderDetail.ThanhTien = orderDetail.SoLuong * orderDetail.DonGia;
                    new ProductDao().UpdateSoLuong(item.Quantity, item.Product.MaSach);
                    order.TongTien += orderDetail.ThanhTien;
                    od.Update(order);
                    orderDetail.MaDonHang = id;
                    detailDao.Insert(orderDetail);
                }
                DeleteAll();
            }
            catch (Exception e)
            {
                return(Redirect("/Cart/Fail"));
            }
            return(Redirect("/Cart/Success"));
        }
        public ActionResult ThanhToan(string shipName, string address, string mobile, string httt, string htgh)
        {
            var od         = new OrderDao();
            var session    = (AccLogin)Session[CommonConstants.Account_Session];
            var dondathang = new DatHang();

            dondathang.CustomerID = new UserDao().GetCus(session.UserName).ID;
            dondathang.CreateDate = DateTime.Now;
            dondathang.LastName   = shipName;
            dondathang.Address    = address;
            dondathang.Phone      = mobile;
            dondathang.Papyment   = httt;


            try
            {
                var     soDH = od.Insert(dondathang);
                var     cart = (List <CartItem>)Session[CartSession];
                var     chitietDao = new OrderDetailDao();
                decimal total = 0;
                string  tenmonan = null, gia = null;
                foreach (var item in cart)
                {
                    decimal thanhtien = 0;
                    var     chitiet   = new ThongTinDatHang();
                    chitiet.OrderID  = soDH;
                    chitiet.FoodID   = item.Monan.ID;
                    chitiet.Price    = item.Monan.Price;
                    chitiet.Quantity = item.SoLuong;
                    thanhtien       += item.Monan.Price.Value * item.SoLuong;
                    od.InsertSLBan(item.Monan.ID, item.SoLuong);
                    chitietDao.Insert(chitiet);

                    total    += (item.Monan.Price.GetValueOrDefault(0) * item.SoLuong);
                    tenmonan += item.Monan.Name + "<br />";
                    gia      += item.Monan.Price.GetValueOrDefault(0).ToString("N0") + "<br />";
                }
                Session[CartSession] = null;
            }
            catch (Exception)
            {
                return(Redirect("/loi-thanh-toan"));
            }
            return(RedirectToAction("DatHangThanhCong", "Cart"));
        }
예제 #30
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();

            order.CreatedDate = 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[CommonConstants.CartSession];
                var     detailDao = new 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.Quatity   = item.Quatity;
                    detailDao.Insert(orderDetail);

                    total += (item.Product.Price.GetValueOrDefault(0) * item.Quatity);
                }

                string content = MergeData.MergeTemplate("~/Assets/Client/template/neworder.html", shipName, mobile, email, address, total.ToString("N0"));

                var toEmail = ConfigurationManager.ConnectionStrings["ToEmailAddress"].ToString();

                new MailHelper().SenMail(email, "Đơn hàng mới từ OnlineShop", content);
                new MailHelper().SenMail(toEmail, "Đơn hàng mới từ OnlineShop", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("loi-thanh-toan"));
            }

            Session[CommonConstants.CartSession] = null;
            return(Redirect("hoan-thanh"));
        }
예제 #31
0
        public ActionResult Payment(string shipName, string mobile, string address, string email)
        {
            var order = new Order();
            order.CreatedDate = 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 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("~/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"));

                new MailHelper().SendEmail(email, "Đơn hàng mới từ OnlineShop",content);
            }
            catch (Exception ex)
            {
                //ghi log
                return Redirect("/loi-thanh-toan");
            }
            return Redirect("/hoan-thanh");
        }