Esempio n. 1
0
        public async Task <IActionResult> GetFreight(int CartTotals)
        {
            // 9-2.系統在Get Action【Cart/GetFreight】讀取運費:
            OrderFreightViewModel ofvm = await IPR.GetOrderFreight(CartTotals);

            // 9-3.系統回傳json( new { Freight=9-2讀取值})
            return(Json(new { Freight = ofvm }));
        }
Esempio n. 2
0
        public async Task <OrderFreightViewModel> GetOrderFreight(decimal ProductFee)
        {
            OrderFreightViewModel ret = null;

            try
            {
                using (SqlConnection con = new SqlConnection(constr))
                {
                    var p = new DynamicParameters();
                    p.Add("@ProductFee", ProductFee, dbType: DbType.Decimal, direction: ParameterDirection.Input);
                    p.Add("@r", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);
                    await con.OpenAsync();

                    IEnumerable <OrderFreightViewModel> tmp = await con.QueryAsync <OrderFreightViewModel>("sp_GetOrderFreight", p, commandType : CommandType.StoredProcedure);

                    ret = tmp.FirstOrDefault <OrderFreightViewModel>();
                }
            }
            catch (Exception)
            {
                ret = null;
            }
            return(ret);
        }
Esempio n. 3
0
        public async Task <IActionResult> Index(string MemberMobile, List <CartsViewModel> Carts)
        {
            List <CartListViewModel> lstCLVM = new List <CartListViewModel>();
            CartListViewModel        CLVM;
            MemberViewModel          MVM = null;

            if (MemberMobile != "" && MemberMobile != null)
            {
                // 3-1.系統在Action【Cart/Index】判斷MemberMobile!=""。
                // 4.系統在Action【Cart/Index】讀取購物車清單。
                lstCLVM = await IMER.GetCartList(MemberMobile);

                // 4-1.系統讀取會員基本資料。
                MVM = await IMER.GetMember(MemberMobile);
            }
            else
            {
                // 3-1a.系統在Action【Cart/Index】判斷MemberMobile!=""
                //  3-1a-1.系統將carts轉換為List<CartListViewModel>。
                foreach (CartsViewModel item in Carts)
                {
                    CLVM                = new CartListViewModel();
                    CLVM.ProductId      = item.productId;
                    CLVM.Product        = item.product;
                    CLVM.ProducSizeId   = item.sizeId;
                    CLVM.ProductColorId = item.colorId;
                    CLVM.Quantity       = item.quantity;
                    CLVM.Price          = item.price;
                    CLVM.ProductSize    = item.size;
                    CLVM.ProductColor   = item.color;
                    lstCLVM.Add(CLVM);
                }
                //  3-1a-2.回4-2。
            }
            // 4-2.系統讀取運費:
            int total = 0;

            foreach (var item in lstCLVM)
            {
                total += (item.Quantity * item.Price);
            }
            OrderFreightViewModel ofvm = await IPR.GetOrderFreight(total);

            // 5.系統在Action【Cart/Index】依4讀取值(List<CartListViewModel>)中每一筆記錄之ProductId,
            //  讀取對應之List<ProductSizeViewModel>與List<ProductColorViewModel>再分別指定給List<CartListViewModel>中的lstPSVM和lstPCVM。
            for (int i = 0; i <= lstCLVM.Count - 1; i++)
            {
                // 5-1.系統讀取商品尺寸資料。
                lstCLVM[i].lstPSVM = await IPRR.GetProductSize(lstCLVM[i].ProductId);

                // 5-2.系統讀取商品顏色資料。
                lstCLVM[i].lstPCVM = await IPRR.GetProductColor(lstCLVM[i].ProductId);
            }

            List <MemberDeliveryAddressListViewModel> MDAL = await IMER.GetMemberDeliveryAddressList(MemberMobile, null, null, null, 0, 10);

            // 5-3.系統回傳View【Cart/Index】,並回傳new CartHomesViewModel { lstCLVM=4傳回值, MVM=4-1傳回值, Freight=4-2讀取值}。
            return(View(new CartHomesViewModel {
                lstCLVM = lstCLVM, MVM = MVM, Freight = ofvm, MDAL = MDAL
            }));
        }