Beispiel #1
0
        public ActionResult LoadCart()
        {
            UserCartClient UC = new UserCartClient();

            ViewBag.Cart = UC.LoadCart(Convert.ToInt32(Session["userID"]));
            return(PartialView());
        }
        public ActionResult Checkout(string shop_List, string delivery_List)
        {
            int address_ID = Convert.ToInt32(Session["Address_ID"].ToString());
            var check      = CheckAvailableItems();

            if (check == null)
            {
                var shop     = shop_List.TrimEnd().Split(' ');
                var delivery = delivery_List.TrimEnd().Split(' ');

                var shopAndDelivery = shop.Zip(delivery, (s, d) => new { Shop = s, Delivery = d });

                UserCartClient UC         = new UserCartClient();
                var            cart_Items = UC.LoadCart(Convert.ToInt32(Session["userID"]));

                foreach (var i in shopAndDelivery)
                {
                    BuyerOrders buyerOrders = new BuyerOrders();
                    string      uniqueID    = GenerateOrderID();
                    buyerOrders.Order_ID     = uniqueID;
                    buyerOrders.User_ID      = Convert.ToInt32(Session["userID"]);
                    buyerOrders.Store_ID     = Convert.ToInt32(i.Shop);
                    buyerOrders.delivery     = Convert.ToInt32(i.Delivery);
                    buyerOrders.payment      = Session["payment"].ToString();
                    buyerOrders.created_date = DateTime.Now;
                    buyerOrders.decription   = "";
                    buyerOrders.status       = 1;
                    buyerOrders.Address_ID   = address_ID;
                    buyerOrders.Total_Order  = 0;
                    BuyerOrdersViewModel bovm = new BuyerOrdersViewModel();
                    bovm.buyerOrders = buyerOrders;
                    BuyerOrdersClient BOC = new BuyerOrdersClient();
                    BOC.Create(bovm.buyerOrders);

                    foreach (var item in cart_Items)
                    {
                        if (item.Store_ID == Convert.ToInt32(i.Shop))
                        {
                            BuyerOrderItems orderItems = new BuyerOrderItems();
                            orderItems.Order_ID = uniqueID;
                            orderItems.Item_ID  = item.ItemID;
                            orderItems.price    = item.Price;
                            orderItems.quantity = item.Quantity;
                            orderItems.discount = 0;
                            orderItems.total    = item.Price * item.Quantity + orderItems.discount;
                            orderItems.status   = 1;
                            BuyerOrderItemsViewModel boivm = new BuyerOrderItemsViewModel();
                            boivm.orderItems = orderItems;
                            BuyerOrderItemsClient BOIC = new BuyerOrderItemsClient();
                            BOIC.Create(boivm.orderItems);
                        }
                    }
                }

                return(Content("Success!!!"));
            }
            return(Content("out of order"));
        }
Beispiel #3
0
        public ActionResult TotalCost()
        {
            UserCartClient UC        = new UserCartClient();
            var            userCarts = UC.LoadCart(Convert.ToInt32(Session["userID"]));
            float          total     = 0;

            foreach (var item in userCarts)
            {
                total += item.Price * item.Quantity;
            }
            ViewBag.Total = total;
            return(PartialView());
        }
Beispiel #4
0
 public ActionResult CountCartItem()
 {
     if (Session["userID"] == null)
     {
         ViewBag.Count = 0;
     }
     else
     {
         UserCartClient UC   = new UserCartClient();
         var            list = UC.LoadCart(Convert.ToInt32(Session["userID"]));
         ViewBag.Count = list.Count();
     }
     return(PartialView());
 }
        // kiem tra so luong hang hoa tuong ung voi san pham trong gio hang
        public List <int> CheckAvailableItems()
        {
            List <int>     outOfOrder = default;
            UserCartClient UC         = new UserCartClient();
            var            cart_Items = UC.LoadCart(Convert.ToInt32(Session["userID"]));
            ProductClient  PC         = new ProductClient();

            foreach (var item in cart_Items)
            {
                var check = PC.find(item.ItemID);
                foreach (var i in check)
                {
                    if (i.Amount < item.Quantity)
                    {
                        outOfOrder.Add(item.ItemID);
                    }
                }
            }
            return(outOfOrder);
        }
        // GET: Buyer/CartCheckout
        public ActionResult Index()
        {
            Session["payment"] = "cod";
            UserCartClient UC         = new UserCartClient();
            var            cart_Items = UC.LoadCart(Convert.ToInt32(Session["userID"]));
            // get shop_id of item in cart
            List <int> shop_IDs = new List <int>();

            foreach (UserCart item in cart_Items)
            {
                if (!shop_IDs.Any(id => id == item.Store_ID))
                {
                    shop_IDs.Add(item.Store_ID);
                }
            }
            ViewBag.Shops = shop_IDs;
            ViewBag.Items = cart_Items;

            BuyerAddressClient buyerAddressClient = new BuyerAddressClient();
            var addressList = buyerAddressClient.find(Convert.ToInt32(Session["userID"]));

            ViewBag.Address = addressList;
            return(View());
        }
        private Payment CreatePayment(APIContext apiContext, string redirectUrl)
        {
            string shop_List       = Session["shop_List"].ToString();
            string delivery_List   = Session["delivery_List"].ToString();
            double shipping        = 0;
            var    shop            = shop_List.TrimEnd().Split(' ');
            var    delivery        = delivery_List.TrimEnd().Split(' ');
            var    shopAndDelivery = shop.Zip(delivery, (s, d) => new { Shop = s, Delivery = d });

            foreach (var i in shopAndDelivery)
            {
                shipping += 12000;
            }

            var itemList = new ItemList()
            {
                items = new List <Item>()
            };
            //Các giá trị bao gồm danh sách sản phẩm, thông tin đơn hàng
            //Sẽ được thay đổi bằng hành vi thao tác mua hàng trên website
            UserCartClient UC             = new UserCartClient();
            var            cart_Items     = UC.LoadCart(Convert.ToInt32(Session["userID"]));
            double         checkout_total = 0;

            foreach (var item in cart_Items)
            {
                var price = Convert.ToDouble(CurrencyConversion(item.Price));
                checkout_total += price * item.Quantity;
                itemList.items.Add(new Item()
                {
                    //Thông tin đơn hàng
                    name     = item.Name,
                    currency = "USD",
                    price    = price.ToString(),
                    quantity = item.Quantity.ToString(),
                    sku      = "sku"
                });
            }
            shipping = Convert.ToDouble(CurrencyConversion(shipping));
            //Hình thức thanh toán qua paypal
            var payer = new Payer()
            {
                payment_method = "paypal"
            };
            // Configure Redirect Urls here with RedirectUrls object
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };
            //các thông tin trong đơn hàng
            var details = new Details()
            {
                tax      = "0",
                shipping = shipping.ToString(),
                subtotal = checkout_total.ToString()
            };
            //Đơn vị tiền tệ và tổng đơn hàng cần thanh toán
            var amount = new Amount()
            {
                currency = "USD",
                total    = (shipping + checkout_total).ToString(), // Total must be equal to sum of shipping, tax and subtotal.
                details  = details
            };
            var transactionList = new List <Transaction>();

            //Tất cả thông tin thanh toán cần đưa vào transaction
            transactionList.Add(new Transaction()
            {
                description    = "Thanh toan Paypal",
                invoice_number = "#a5D30xCdv6",
                amount         = amount,
                item_list      = itemList
            });
            this.payment = new Payment()
            {
                intent        = "sale",
                payer         = payer,
                transactions  = transactionList,
                redirect_urls = redirUrls
            };
            // Create a payment using a APIContext
            return(this.payment.Create(apiContext));
        }