Beispiel #1
0
        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 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"));
        }
Beispiel #3
0
        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"));
        }
Beispiel #4
0
        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"));
        }
        void setOrdelDetail(long res)
        {
            var items          = (List <CartItem>)Session[CARTSESSION];
            var orderDetailDAO = new OrderDetailDAO();

            foreach (var item in items)
            {
                var orderDetail = new OrderDetail();
                orderDetail.ProductID = item.product.ProductID;
                orderDetail.OrderID   = res;
                orderDetail.Quanlity  = item.quanlity;
                if (item.product.PromotionPrice == 0)
                {
                    orderDetail.Price = item.product.Price;
                }
                else
                {
                    orderDetail.Price = item.product.PromotionPrice;
                }
                orderDetailDAO.Create(orderDetail);
            }
            Session[CARTSESSION] = null;
        }