Exemple #1
0
        public IActionResult RemoveItem(string cartID, int spID)
        {
            bool KM     = false;
            bool falshD = false;
            var  myItem = (from c in _context.CartItems where c.CartId == cartID && c.Idsanpham == spID select c).FirstOrDefault();

            if (myItem != null)
            {
                CartView CartView = new CartView();
                CartView.cartItemsModelViews = new List <CartItemsModelView>();
                _context.CartItems.Remove(myItem);
                _context.SaveChanges();
                var returnitems = _context.CartItems.Where(
                    c => c.CartId == cartID).ToList();
                foreach (CartItems cart in returnitems)
                {
                    var sp = _context.SanPham.FirstOrDefault(n => n.IdSp == cart.Idsanpham);

                    CartItemsModelView itemoncart = new CartItemsModelView
                    {
                        CartID    = cart.CartId,
                        Quantity  = cart.Quantity.Value,
                        SpId      = cart.Idsanpham,
                        ImgLink   = _context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).AnhSp,
                        PricesP   = _context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).GiaSp,
                        UnitPrice = float.Parse(_context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).GiaSp) * cart.Quantity.Value,
                        TenSP     = _context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).TenSp,
                    };
                    if (sp.FlashDealBd.HasValue && sp.FlashDealKt.Value >= DateTime.Now)
                    {
                        itemoncart.giaFlashDeal = sp.GiaFlashDeal;
                        itemoncart.flashDeal    = true;
                        falshD = true;
                        itemoncart.UnitPrice = float.Parse(itemoncart.giaFlashDeal) * cart.Quantity.Value;
                    }
                    else if (sp.NgayBdKm.HasValue && sp.NgayKtKm.Value >= DateTime.Now)
                    {
                        itemoncart.giaKM     = sp.KhuyenMai;
                        itemoncart.khuyenMai = true;
                        KM = true;
                        itemoncart.ngayKTKhuyenmai = sp.NgayKtKm.Value;
                        itemoncart.UnitPrice       = float.Parse(itemoncart.giaKM) * cart.Quantity.Value;
                    }
                    else
                    {
                        itemoncart.UnitPrice = float.Parse(_context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).GiaSp) * cart.Quantity.Value;
                    }
                    CartView.cartItemsModelViews.Add(itemoncart);
                    CartView.total = GetTotal(KM, falshD);
                }
                ;

                if (returnitems.Count <= 0)
                {
                    return(Ok("Cart Empty"));
                }
                return(Ok(CartView));
            }
            return(BadRequest("Error"));
        }
Exemple #2
0
        public void Can_Remove_Line()
        {
            // Arrange - create some test products
            Product p1 = new Product {
                ProductID = 1, Name = "P1"
            };
            Product p2 = new Product {
                ProductID = 2, Name = "P2"
            };
            Product p3 = new Product {
                ProductID = 3, Name = "P3"
            };

            // Arrange - create a new cart
            CartView target = new CartView();

            // Arrange - add some products to the cart
            target.AddItem(p1, 1);
            target.AddItem(p2, 3);
            target.AddItem(p3, 5);
            target.AddItem(p2, 1);

            // Act
            target.RemoveLine(p2);

            // Assert
            Assert.AreEqual(target.Lines.Where(c => c.Product.Name == p2.Name).Count(), 0);
            Assert.AreEqual(target.Lines.Count(), 2);
        }
Exemple #3
0
        public void Test_Cart_Serialization()
        {
            // Arrange - create some test products
            Product p1 = new Product {
                ProductID = 1, Name = "P1", Price = 100M
            };
            Product p2 = new Product {
                ProductID = 2, Name = "P2", Price = 50M
            };

            // Arrange - create a new cart
            CartView target = new CartView();

            // Arrange - add some items
            target.AddItem(p1, 1);
            target.AddItem(p2, 1);

            var jsonString = JsonConvert.SerializeObject(target);

            Assert.IsTrue(jsonString.GetType() == typeof(string));

            var     cartViewObject = JsonConvert.DeserializeObject <CartView>(jsonString);
            decimal price          = cartViewObject.Lines.Where(p => p.Product.Name == "P1").Select(p => p.Product.Price).FirstOrDefault();

            Assert.AreEqual(100M, price);
        }
Exemple #4
0
        public async Task <IActionResult> Index()
        {
            string user = HttpContext.Session.GetString("Id");

            var model = from m in _context.Cart
                        select m;

            model = model.Where(m => m.User == user);

            List <Cart> carts = await model.ToListAsync();

            List <CartView> cartViews = new List <CartView>();

            foreach (Cart cart in carts)
            {
                Product product = await _context.Product.FindAsync(cart.Product);

                CartView cartView = new CartView();
                cartView.Id       = cart.Id;
                cartView.Name     = product.Name;
                cartView.Note     = product.Note;
                cartView.Image    = product.Image;
                cartView.Price    = product.Price;
                cartView.Quantity = cart.Quantity;
                cartView.Total    = product.Price * cart.Quantity;
                cartViews.Add(cartView);
            }

            return(View(cartViews));
        }
Exemple #5
0
        // 渲染购物车里的商品
        public List <CartView> GetCartProduct(string buyerid)
        {
            List <CartView> shopCarts = new List <CartView>();    //  购物车信息显示类 列表

            List <AddShoppingCart> carts = _context.AddShoppingCarts.Where(x => x.BuyerId == buyerid).ToList();

            foreach (AddShoppingCart cart in carts)
            {
                Commodity commodity = _context.Commodities.Where(x => x.CommodityId == cart.CommodityId).FirstOrDefault();

                Shop shop = _context.Shops.Where(x => x.ShopId == commodity.ShopId).FirstOrDefault();

                CartView cartview = new CartView
                {
                    errorCode     = 0,
                    BuyerId       = cart.BuyerId,
                    commodityId   = cart.CommodityId,
                    CommodityName = commodity.Name,
                    DateCreated   = cart.DateCreated,
                    ShopName      = shop.Name,
                    shopId        = shop.ShopId,
                    imgUrl        = commodity.Url,
                    amount        = cart.Quantity,
                    Price         = commodity.Price * cart.Quantity
                };

                shopCarts.Add(cartview);
            }
            return(shopCarts);
        }
Exemple #6
0
 public void Post([FromBody] CartView model)
 {
     if (model != null)
     {
         cbl.AddToCart(model);
     }
 }
        // GET: Carts/Create
        public async Task <IActionResult> Create(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var product = await _context.Products.FindAsync(id);

            if (product == null)
            {
                return(NotFound());
            }
            var cartView = new CartView {
                UserId    = 1,
                ProductId = product.Id,
                Active    = true
            };
            var cart = new Cart();

            cart.Map(cartView);
            _context.Add(cart);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemple #8
0
        public async Task <IActionResult> AddToCart(int id)
        {
            Product p = new Product();

            if (HttpContext.Session.GetString("token") == null)
            {
                return(RedirectToAction("Login", "Authentication"));
            }
            string today = DateTime.Now.AddDays(1).ToString("yyyy'-'MM'-'dd");

            ViewBag.Min = today;
            var response = await _productProvider.GetProductById(id, HttpContext.Session.GetString("token"));

            CartView cart = new CartView();

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var JsonContent = await response.Content.ReadAsStringAsync();

                p = JsonConvert.DeserializeObject <Product>(JsonContent);
                cart.ProductName = p.Name;
                cart.Description = p.Description;
                cart.Price       = p.Price;
                cart.imagename   = p.Image_Name;
            }
            cart.Product_Id    = id;
            cart.Customer_Id   = Convert.ToInt32(HttpContext.Session.GetInt32("custId"));
            cart.Customer_Name = Convert.ToString(HttpContext.Session.GetString("Username"));
            return(View(cart));
        }
Exemple #9
0
 public IHttpActionResult PostCart(List <CartVM> model)
 {
     if (model != null)
     {
         var cart = new CartView();
         cart.Cart = new List <CartVM>();
         foreach (var m in model)
         {
             var item = db.Items.Find(m.Id);
             cart.Cart.Add(new CartVM
             {
                 Id    = item.ItemID,
                 Name  = item.Name,
                 Price = item.Price,
                 Total = m.Count * item.Price,
                 Count = m.Count
             });
         }
         cart.Total = cart.Cart.Sum(c => c.Total);
         return(Ok(cart));
     }
     else
     {
         return(Ok());
     }
 }
        public void BindGrid()
        {
            try
            {
                cartSub.Style.Remove("text-decoration");
                discSub.Text = "";

                if (Request.Cookies.Get("cartKey") != null)
                {
                    Guid cartKey = Guid.Parse(Request.Cookies["cartKey"].Value);

                    List <SqlParameter> p = new List <SqlParameter>();
                    p.Add(new SqlParameter("@GUID", cartKey));

                    DataTable cartDetails = DB.Get("CartSummaryGet", p.ToArray());
                    CartView.DataSource = cartDetails;

                    if (cartDetails != null && cartDetails.Rows.Count > 0)
                    {
                        p = new List <SqlParameter>();
                        p.Add(new SqlParameter("@CacheID", cartKey));

                        decimal   Subtotal = 0M;
                        DataTable dtSub    = DB.Get("CartSubtotalGet", p.ToArray());
                        if (dtSub != null && dtSub.Rows.Count > 0)
                        {
                            string  strSub     = dtSub.Rows[0][0].ToString();
                            decimal tryDecimal = 0M;
                            if (decimal.TryParse(strSub, out tryDecimal))
                            {
                                Subtotal = tryDecimal;
                            }
                        }

                        cartSub.Text = "$" + Subtotal.ToString("0.00");

                        DataRow dr = cartDetails.Rows[0];
                        if (!string.IsNullOrEmpty(dr["DiscountID"].ToString()))
                        {
                            decimal CartTotal = DiscountUtils.CalculateDiscountTotal((int)dr["DiscountID"], cartKey);
                            cartSub.Style.Add("text-decoration", "line-through");
                            discSub.Text = "W/ Discount: $" + CartTotal.ToString("0.00");
                        }
                    }
                    else
                    {
                        cartSub.Text = "$0.00";
                    }
                }
                else
                {
                    CartView.DataSource = string.Empty;
                }
                CartView.DataBind();
            }
            catch (Exception ex)
            {
                LoggingUtil.InsertError(ex);
            }
        }
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            ISession session = bindingContext.ActionContext.HttpContext.Session;

            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }
            CartView cart = null;

            if (session != null)
            {
                cart = session.GetString("Cart") != null?JsonConvert.DeserializeObject <CartView>(session.GetString("Cart")) : null;
            }
            if (cart == null)
            {
                cart = new CartView();
                if (session != null)
                {
                    session.SetString(sessionKey, JsonConvert.SerializeObject(cart));
                }
            }
            //bindingContext.ModelState.SetModelValue(sessionKey,  cart);
            bindingContext.Result = ModelBindingResult.Success(cart);
            return(Task.CompletedTask);
        }
Exemple #12
0
    private void AddItem(Cart cart)
    {
        CartView cartView = Instantiate(_cartTemplate, _itemContainer.transform);

        cartView.Render(cart);
        cartView.ButtonSellClick += OnButtonSellClick;
    }
        public async Task <ActionResult> Cart(Guid?customerId)
        {
            try
            {
                CartView model = null;
                if (customerId == null)
                {
                    var currentCustomerId = await GetCustomerId();

                    model = await _cartService.LoadCart(currentCustomerId);

                    if (model == null || !_cartService.HasItems(model))
                    {
                        return(PartialView(ViewNameConstant.PREVIEW_CART, null));
                    }
                    _cartService.UpdateTotalPrice(model);
                    return(PartialView(ViewNameConstant.PREVIEW_CART, model));
                }
                model = await _cartService.LoadCart(customerId.Value);

                if (model != null && _cartService.HasItems(model))
                {
                    _cartService.UpdateTotalPrice(model);
                    return(PartialView(ViewNameConstant.PREVIEW_CART, model));
                }
                return(PartialView(ViewNameConstant.PREVIEW_CART, null));
            }catch (Exception ex)
            {
                return(ReturnFailJson(ex.Message));
            }
        }
        // GET: /Cart/DecrementProduct
        public ActionResult DecrementProduct(int productId)
        {
            // Init cart
            List <CartView> cart = Session["cart"] as List <CartView>;

            using (DBLayer db = new DBLayer())
            {
                // Get model from list
                CartView model = cart.FirstOrDefault(x => x.ProductId == productId);

                // Decrement qty
                if (model.Quantity > 1)
                {
                    model.Quantity--;
                }
                else
                {
                    model.Quantity = 0;
                    cart.Remove(model);
                }

                // Store needed data
                var result = new { qty = model.Quantity, price = model.Price };

                // Return json
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #15
0
 public void SetCartCurrency(CartView cart, string currency)
 {
     if (ComponentsHelper.Currency.ContainsKey(currency))
     {
         cart.Currency = currency;
     }
 }
Exemple #16
0
        public async Task GetOrCreateDefaultShippingAddress(CartView cart)
        {
            if (!HasShippingAddressSelected(cart))
            {
                var shipping = GetOrCreateDefaultShipping(cart);
                shipping.ShippingAddress = new AddressView();
                var currentContact = await _userContext.GetCurrentContact();

                if (currentContact != null)
                {
                    var selectedContact = currentContact.ShippingAddress != null ? currentContact.ShippingAddress : currentContact.BillingAddress;
                    if (selectedContact != null)
                    {
                        shipping.ShippingAddress = new AddressView()
                        {
                            CityOrTownOrVillage = selectedContact.CityOrTownOrVillage,
                            CountryCode         = string.Empty,
                            CountryName         = string.Empty,
                            Email                = selectedContact.Email,
                            FirstName            = selectedContact.FirstName,
                            LastName             = selectedContact.LastName,
                            PhoneNumber          = selectedContact.PhoneNumber,
                            PostCode             = selectedContact.PostCode,
                            Prefecture           = selectedContact.Prefecture,
                            StreetAndHouseNumber = selectedContact.StreetAndHouseNumber
                        };
                    }
                }
            }
        }
Exemple #17
0
 public ViewResult Checkout(CartView cart)
 {
     return(View(new ShippingDetailsView()
     {
         Line1 = "1780 Tate Rd", Name = "Adam"
     }));
 }
        public ServiceResult CheckOut(CartView cart)
        {
            string       ipAddress = new NetworkHelper().GetClientIpAddress(Request);
            StoreManager sm        = new StoreManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            return(sm.ProcessPayment(cart, ipAddress));
        }
Exemple #19
0
        public ServiceResult CheckOut(CartView cart)
        {
            string       ipAddress = new NetworkHelper().GetClientIpAddress(Request);
            StoreManager sm        = new StoreManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            return(sm.ProcessPayment(cart, ipAddress));
        }
 private async Task DeleteCartView(CartView cartView)
 {
     await _processor.ProcessCommandAsync <DeleteCartCommand>(new DeleteCartCommand()
     {
         CartView = cartView
     });
 }
        public string AddToCart(CartView values)
        {
            Cart c       = new Cart();
            var  userkey = model.Customer.Where(x => x.EmailId == values.emailId).Select(u => u.UserId).SingleOrDefault();

            c.CustomerID = userkey;
            var stock = model.Product.Where(p => p.ProductId == values.productId).Select(q => q.Quantity).SingleOrDefault();

            c.PID = values.productId;
            // var duplicate = model.Cart.Where(cus => cus.CustomerID == userkey).Select(p => p.PID);
            var proexists = ProductExist(values.productId);

            if (proexists)
            {
                var tqty = model.Cart.Where(pd => pd.PID == values.productId).FirstOrDefault();
                tqty.Quantity   = tqty.Quantity + values.quantity;
                tqty.TotalPrice = tqty.Quantity * tqty.UnitPrice;
            }
            else
            {
                var prodprice = model.Product.Where(p => p.ProductId == values.productId).Select(d => d.Price).SingleOrDefault();
                c.UnitPrice  = prodprice;
                c.TotalPrice = c.UnitPrice * values.quantity;
                c.Quantity   = values.quantity;
                model.Cart.Add(c);
            }
            model.SaveChanges();
            return("success");
        }
Exemple #22
0
        private UserControl GetView(NavigateInfo navigationInfo)
        {
            switch (navigationInfo.ScreenName)
            {
            case "SelectCustomer":
                var view      = new CustomersView();
                var viewModel = new CustomersViewModel(ServiceLocator.Current.GetInstance <IWebservice>(), navigationInfo.CurrentCart);
                view.DataContext = viewModel;
                return(view);

            case "ProductSelection":
                var productsView      = new ProductsView();
                var productsViewModel = new ProductsViewModel(ServiceLocator.Current.GetInstance <IWebservice>(), navigationInfo.CurrentCart);
                productsView.DataContext = productsViewModel;
                return(productsView);

            case "CartCheckout":
                var cartView      = new CartView();
                var cartViewModel = new CartViewModel(ServiceLocator.Current.GetInstance <IWebservice>(), navigationInfo.CurrentCart, navigationInfo.CurrentCustomer);
                cartView.DataContext = cartViewModel;
                return(cartView);
            }

            return(null);
        }
Exemple #23
0
        public void MergeCart(CartView fromCartView, CartView toCartView)
        {
            var fromShipping = GetOrCreateDefaultShipping(fromCartView);

            if (fromShipping != null && fromShipping.LineItems.Count > 0)
            {
                var toShipping = GetOrCreateDefaultShipping(toCartView);
                foreach (var lineItem in fromShipping.LineItems)
                {
                    var toLineItem = toShipping.LineItems.FirstOrDefault(x => x.Sku.Equals(lineItem.Sku) && x.VariantId.Equals(lineItem.VariantId));
                    if (toLineItem == null)
                    {
                        toShipping.LineItems.Add(new LineItemView()
                        {
                            DisplayName   = lineItem.DisplayName,
                            ExtendedPrice = lineItem.ExtendedPrice,
                            LineItemId    = lineItem.LineItemId,
                            PlacedPrice   = lineItem.PlacedPrice,
                            Quantity      = lineItem.Quantity,
                            Sku           = lineItem.Sku,
                            VariantId     = lineItem.VariantId,
                            ImageUrl      = lineItem.ImageUrl
                        });
                    }
                    else
                    {
                        toLineItem.Quantity      = toLineItem.Quantity + lineItem.Quantity;
                        toLineItem.ExtendedPrice = toLineItem.Quantity * toLineItem.PlacedPrice;
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lDiscount.Visible = false;
            if (!string.IsNullOrWhiteSpace(Request.Params["paymentId"].ToString()) && !string.IsNullOrWhiteSpace(Request.Params["PayerID"].ToString()))
            {
                paymentid.Value = Request.Params["paymentId"].ToString();
                payerid.Value   = Request.Params["PayerID"].ToString();
            }
            else
            {
                Response.Redirect("~/Shop", false);
            }

            if (Request.Cookies["cartKey"] != null)
            {
                Guid cartKey          = Guid.Parse(Request.Cookies["cartKey"].Value);
                List <SqlParameter> p = new List <SqlParameter>();
                p.Add(new SqlParameter("@GUID", cartKey));

                DataTable cartDetails = DB.Get("CartSummaryGet", p.ToArray());
                CartView.DataSource = cartDetails;
                CartView.DataBind();

                p = new List <SqlParameter>();
                p.Add(new SqlParameter("@CacheID", cartKey));

                decimal   Subtotal = 0M;
                DataTable dtSub    = DB.Get("CartSubtotalGet", p.ToArray());
                if (dtSub != null && dtSub.Rows.Count > 0)
                {
                    string  strSub     = dtSub.Rows[0][0].ToString();
                    decimal tryDecimal = 0M;
                    if (decimal.TryParse(strSub, out tryDecimal))
                    {
                        Subtotal = tryDecimal;
                    }
                }

                DataRow dr       = cartDetails.Rows[0];
                decimal Discount = 0M;
                if (!string.IsNullOrEmpty(dr["DiscountID"].ToString()))
                {
                    Discount = DiscountUtils.CalculateDiscountTotal((int)dr["DiscountID"], cartKey);
                }

                decimal Shipping = ScalablePressUtils.GetShippingQuote(cartKey);
                if (Shipping > 0M)
                {
                    lSubTotal.Text = "Subtotal: $" + Subtotal.ToString("0.00");
                    if (Discount > 0)
                    {
                        lDiscount.Text    = "Discount: -$" + Discount.ToString("0.00");
                        lDiscount.Visible = true;
                    }
                    lShipTotal.Text = "S&H: $" + Shipping.ToString("0.00");
                    lTotal.Text     = "Total: $" + Math.Round(Subtotal - Discount + Shipping, 2, MidpointRounding.AwayFromZero).ToString("0.00");
                }
            }
        }
Exemple #25
0
        public CartView UpdateCartItems([FromBody] CartItemsModelView itemUpdate)
        {
            //ModelState.Remove("TenSP");
            //ModelState.Remove("ImgLink");
            //ModelState.Remove("PricesP");
            //ModelState.Remove("UnitPrice");
            bool     KM       = false;
            bool     falshD   = false;
            CartView CartView = new CartView();

            CartView.cartItemsModelViews = new List <CartItemsModelView>();
            var caritems = _context.CartItems.SingleOrDefault(
                c => c.CartId == itemUpdate.CartID && c.Idsanpham == itemUpdate.SpId);

            caritems.Quantity = itemUpdate.Quantity;
            _context.SaveChanges();

            var returnitems = _context.CartItems.Where(
                c => c.CartId == itemUpdate.CartID).ToList();

            foreach (CartItems cart in returnitems)
            {
                var sp = _context.SanPham.FirstOrDefault(n => n.IdSp == cart.Idsanpham);
                CartItemsModelView itemoncart = new CartItemsModelView
                {
                    CartID   = cart.CartId,
                    Quantity = cart.Quantity.Value,
                    SpId     = cart.Idsanpham,
                    ImgLink  = _context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).AnhSp,
                    PricesP  = _context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).GiaSp,
                    //UnitPrice = float.Parse(_context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).GiaSp) * cart.Quantity.Value,
                    TenSP = _context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).TenSp,
                };

                if (sp.FlashDealBd.HasValue && sp.FlashDealKt.Value >= DateTime.Now)
                {
                    itemoncart.giaFlashDeal = sp.GiaFlashDeal;
                    falshD = true;
                    itemoncart.flashDeal = true;
                    itemoncart.UnitPrice = float.Parse(itemoncart.giaFlashDeal) * cart.Quantity.Value;
                }
                else if (sp.NgayBdKm.HasValue && sp.NgayKtKm.Value >= DateTime.Now)
                {
                    itemoncart.giaKM     = sp.KhuyenMai;
                    itemoncart.khuyenMai = true;
                    KM = true;
                    itemoncart.ngayKTKhuyenmai = sp.NgayKtKm.Value;
                    itemoncart.UnitPrice       = float.Parse(itemoncart.giaKM) * cart.Quantity.Value;
                }
                else
                {
                    itemoncart.UnitPrice = float.Parse(_context.SanPham.FirstOrDefault(n => n.IdSp.Equals(cart.Idsanpham)).GiaSp) * cart.Quantity.Value;
                }
                CartView.cartItemsModelViews.Add(itemoncart);
                CartView.total = GetTotal(KM, falshD);
            }
            ;
            return(CartView);
        }
Exemple #26
0
        public ViewResult Index(CartView cart, string returnUrl)
        {
            var viewModel = new CartIndexViewModel {
                Cart      = cart,
                ReturnUrl = returnUrl
            };

            return(View(viewModel));
        }
Exemple #27
0
        public static void SaveMap(this Cart destination, CartView source)
        {
            var now = DateTime.UtcNow;

            destination.UserId     = source.UserId;
            destination.ProductId  = source.ProductId;
            destination.ModifiedAt = now;
            destination.Active     = source.Active;
        }
Exemple #28
0
        public void UpdateTotalPrice(CartView cart)
        {
            var shipping = GetOrCreateDefaultShipping(cart);

            foreach (var lineItem in shipping.LineItems)
            {
                lineItem.ExtendedPrice = lineItem.Quantity * lineItem.PlacedPrice;
            }
        }
Exemple #29
0
        public static ShoppingCart ToShoppingCart(this CartView cart)
        {
            ShoppingCart shoppingCart = new ShoppingCart();

            foreach (var cartItem in cart.Books)
            {
                shoppingCart.Books.Add(cartItem.ToBook());
            }
            return(shoppingCart);
        }
Exemple #30
0
        public void RemoveToCart(CartView cart, string sku, string variantId)
        {
            var shipping = GetOrCreateDefaultShipping(cart);
            var lineItem = shipping.LineItems.FirstOrDefault(x => x.Sku.Equals(sku) && x.VariantId.Equals(variantId));

            if (lineItem != null)
            {
                shipping.LineItems.Remove(lineItem);
            }
        }
Exemple #31
0
        public ActionResult Index()
        {
            CartView dataForView = new CartView();
            //透過Session取得購物車編號
            var sessionCartInfo = HttpContext.Session["Cart"];
            string cart = (sessionCartInfo != null) ? sessionCartInfo.ToString() : null;
            dataForView.ItemList = cartService.GetItemsFromCart(cart);
            dataForView.isCartSave = cartService.IsCartSaved(User.Identity.Name, cart);

            return View(dataForView);
        }
 public CheckoutViewModel SetCurrentStep(int step)
 {
     if (Cart.OrderDetails.Count == 0 || step < 1) step = 1;
     if (step - LastestStep > 1 || step > Steps.Length) step = LastestStep;
     switch (step)
     {
         case 1:
             StepTitle = "Thống kê giỏ hàng";
             break;
         case 2:
             if (CacheHelper._CacheHelper.GetCustomer().IsLoggedIn)
             {
                 step = 3;
                 break;
             }
             StepTitle = "Thông tin khách hàng";
             break;
         case 3:
             StepTitle = "Thông tin giao hàng";
             break;
         case 4:
             StepTitle = "Xác nhận đơn hàng";
             break;
         case 5:
             StepTitle = "Hoàn tất đặt hàng";
             CartReview = new CartView()
             {
                 ContactNumber = Cart.ContactNumber,
                 CustomerName = Cart.CustomerName,
                 Delivery = Cart.Delivery,
                 OrderNumber = Cart.OrderNumber,
                 ShipmentAddress = Cart.Delivery ? Cart.ShipmentAddress + " " + Cart.ShipmentDistrict :
                                   "Khách nhận hàng tại Giải khát Ngọc Mai",
                 ShipmentDate = Cart.ShipmentDate,
                 Total = Cart.Total
             };
             ClearCart();
             break;
     }
     CurrentStep = step;
     if(CurrentStep == Steps.Length)
     {
         CacheHelper._CacheHelper.SetLastestCheckoutStep(1);
     }
     else if (CurrentStep > LastestStep)
     {
         CacheHelper._CacheHelper.SetLastestCheckoutStep(CurrentStep);
     }
     return this;
 }