コード例 #1
0
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                base.OnLoad(e);

                if (Page.IsPostBack == false)
                {
                    var providerkey = Utils.RequestParam(Context, "provider");
                    if (providerkey != "")
                    {
                        var cartInfo = new CartData(PortalSettings.Current.PortalId);
                        if (cartInfo != null)
                        {
                            cartInfo.SaveModelTransQty();                         // move qty into trans
                            var orderData = cartInfo.ConvertToOrder(StoreSettings.Current.DebugMode);
                            orderData.PaymentProviderKey = providerkey.ToLower(); // provider keys should always be lowecase
                            orderData.SavePurchaseData();
                            PaymentsInterface.Instance(orderData.PaymentProviderKey).RedirectForPayment(orderData);
                        }
                    }
                    else
                    {
                        PageLoad();
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                //display the error on the template (don't want to log it here, prefer to deal with errors directly.)
                var l = new Literal();
                l.Text = exc.ToString();
                Controls.Add(l);
            }
        }
コード例 #2
0
        private static String GetPaymentList(HttpContext context)
        {
            var ajaxInfo      = NBrightBuyUtils.GetAjaxFields(context);
            var themeFolder   = ajaxInfo.GetXmlProperty("genxml/hidden/themefolder");
            var razortemplate = ajaxInfo.GetXmlProperty("genxml/hidden/razortemplate");

            var passSettings = ajaxInfo.ToDictionary();

            foreach (var s in StoreSettings.Current.Settings()) // copy store setting, otherwise we get a byRef assignement
            {
                if (passSettings.ContainsKey(s.Key))
                {
                    passSettings[s.Key] = s.Value;
                }
                else
                {
                    passSettings.Add(s.Key, s.Value);
                }
            }

            var cartInfo = new CartData(PortalSettings.Current.PortalId);

            if (cartInfo != null)
            {
            }

            var strOut = NBrightBuyUtils.RazorTemplRender(razortemplate, 0, "", cartInfo, "/DesktopModules/NBright/NBrightBuy", themeFolder, Utils.GetCurrentCulture(), passSettings);

            return(strOut);
        }
コード例 #3
0
        //GET: Cart
        public ActionResult Cart()
        {
            CartData cart     = (CartData)Session["cart"];
            CartData cartAvai = new CartData();
            CartData cartSold = new CartData();

            if (cart != null)
            {
                for (int i = 0; i < cart.arrCart.Count; i++)
                {
                    Cart        c = (Cart)cart.arrCart[i];
                    tbl_Product p = db.tbl_Product.Find(c.item.id);
                    if (p.amount >= c.amounts)
                    {
                        cartAvai.addWithNum(c.item, c.amounts);
                    }
                    else if (p.amount > 0)
                    {
                        cartAvai.addWithNum(c.item, c.amounts);
                    }
                    else if (p.amount <= 0)
                    {
                        cartSold.addWithNum(c.item, c.amounts);
                    }
                }
            }
            ViewBag.cart = cartAvai;
            return(View());
        }
コード例 #4
0
        public PartialViewResult Cart()
        {
            var session = (UserLogin)Session[CommonConstants.USER_SESSION];
            var list    = new List <CartModel>();

            if (session != null)
            {
                var cart    = new CartData().GetByUserID(session.userID);
                var product = new ProductData().ListAll();
                //var cart = Session[CommonConstants.CartSession];
                //if (cart != null)
                //{
                //    list = (List<CartModel>)cart;
                //}
                foreach (var temp in cart)
                {
                    foreach (var item in product)
                    {
                        if (temp.ProductID == item.ProductID)
                        {
                            var cartModel = new CartModel();
                            cartModel.CartID   = temp.CartID;
                            cartModel.UserID   = session.userID;
                            cartModel.Product  = item;
                            cartModel.Quantity = temp.Quantity;
                            list.Add(cartModel);
                        }
                    }
                }
            }
            return(PartialView(list));
        }
コード例 #5
0
ファイル: DataTests.cs プロジェクト: nickcooksey/UtilityLibs
        public void CartDataTest_filenameok()
        {
            var filename = "filename1.csv";
            var cd       = new CartData(filename);

            Assert.AreEqual(filename, cd.FileName);
        }
コード例 #6
0
        public void MeasureDepthsAtJetLocations(CartData depthData)
        {
            foreach (XSectionPathEntity xpe in this)
            {
                double xMeasure = xpe.CrossLoc;
                for (int i = 1; i < depthData.Count; i++)
                {
                    if ((xpe.CrossLoc >= depthData[i - 1].X && xpe.CrossLoc <= depthData[i].X) ||
                        (xpe.CrossLoc <= depthData[i - 1].X && xpe.CrossLoc >= depthData[i].X))
                    {
                        double denom = (depthData[i].X - depthData[i - 1].X);
                        double m = 0;
                        double radius = 0;
                        if (denom != 0)
                        {
                            m = (depthData[i].Y - depthData[i - 1].Y) / denom;
                            radius = m * (xpe.CrossLoc - depthData[i - 1].X) + depthData[i - 1].Y;
                        }
                        else
                        {
                            radius = (depthData[i].Y + depthData[i - 1].Y) / 2.0;
                        }
                        xpe.CurrentRadius = radius  ;

                        break;
                    }
                }
            }
        }
コード例 #7
0
        // GET: Cart
        public ActionResult ViewCart(string sessionId)
        {
            if (sessionId == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            // get cust id to match cust id w cart id
            Customer          customer = CustomerData.GetCustomerBySessionId(sessionId);
            List <CartDetail> cart     = CartData.GetCart(customer.CustomerId);
            ProductData       pd       = new ProductData();
            List <Product>    products = pd.GetAllProducts();

            foreach (var cartitem in cart)
            {
                cartitem.Product = CartData.GetProductByProductId(cartitem.ProductId);
            }
            int cartQuantity = CartData.GetCartQuantity(customer.CustomerId);

            ViewData["SessionId"]    = sessionId;
            ViewData["cart"]         = cart;
            ViewData["products"]     = products;
            ViewData["cartQuantity"] = cartQuantity;
            ViewData["cid"]          = customer.CustomerId;
            return(View());
        }
コード例 #8
0
        public ActionResult LoginCheckPassword(FormCollection form)
        {
            string username = form["Name"];
            string password = form["Password"];

            using (MD5 md5Hash = MD5.Create())
            {
                string hashedpassword = GetMd5Hash(md5Hash, password);


                if (hashedpassword == UserData.GetPassword(username))
                {
                    //when user submit the correct username and password , we create a new session.

                    Session["username"] = username;
                    DateTime lastlogin = UserData.GetLastLogin(username);
                    DateTime logindate = DateTime.Today;
                    int      bonus     = 0;
                    if (lastlogin != logindate && logindate < lastlogin.AddDays(7))
                    {
                        bonus = 50;
                    }
                    UserData.AddCoin(username, bonus);

                    Session["cart"] = CartData.GetCart(username);
                    Session["coin"] = UserData.GetCoinNum(username);
                    UserData.UpdateLastLogin(username);
                    return(RedirectToAction("ProductList", "Product"));
                }
            }
            TempData["isAuth"] = false;
            return(View("Login"));
        }
コード例 #9
0
        /*
         * To display summary of items before payment
         */
        public IActionResult Index()
        {
            //Retrieve userId and SessionId from cookies
            string sessionId = HttpContext.Request.Cookies["sessionId"];
            string userId    = HttpContext.Request.Cookies["userId"];

            /*
             * Session object allows to query based on user id
             * Although user id is enough, creating a session object allows code reusability
             */
            Session sess = new Session()
            {
                SessionId = sessionId,
                UserId    = userId
            };

            /*Retrieve products from the cart and total number and price of items
             * and Assign to view Data to access from views
             */
            List <ProductInCart> product = CartData.GetAllProducts(sess);
            double sum = CartData.GetCartSum(sess);

            ViewData["product"] = product;
            ViewData["total"]   = sum;
            int totalItems = CartData.GetTotalItems(sess);

            ViewData["TotalItems"] = totalItems;

            ViewData["sessionId"] = sessionId;
            ViewData["UserId"]    = userId;
            return(View());
        }
コード例 #10
0
        public IActionResult Checkout()
        {
            if (!IsUser())
            {
                return(View(index));
            }
            bool check = true;
            List <CartItemDTO> list = new List <CartItemDTO>();

            string[] productDetailID = Request.Form["txtProductDetailID"];
            string[] quantity        = Request.Form["txtQuantity"];
            int      cartID          = new CartData().GetCartIDByUsername(HttpContext.Session.GetString("SessionUser"));

            for (int i = 0; i < productDetailID.Length; i++)
            {
                int pdID = int.Parse(productDetailID[i]);
                int qtt  = int.Parse(quantity[i]);
                list.Add(new CartItemDTO {
                    CartId = cartID, Quantity = qtt, ProductDetailId = pdID
                });
            }
            if (check = new CartItemData().CheckValidCartItems(list))
            {
                ViewBag.UserInfo = new UserData().GetUserInfoByUserID(HttpContext.Session.GetString("SessionUser"));
                ViewBag.Cart     = new CartItemData().GetCartItemsByCartID(cartID);
                return(View());
            }
            else
            {
                ViewBag.Announcement = "Update failed";
            }

            ViewBag.Cart = new CartItemData().GetCartItemsByCartID(cartID);
            return(View("Cart"));
        }
コード例 #11
0
        public IActionResult AddToCart()
        {
            if (!IsUser())
            {
                return(View(login));
            }
            int cartID = new CartData().GetCartIDByUsername(HttpContext.Session.GetString("SessionUser"));

            int quantity        = int.Parse(Request.Form["txtQuantity"]);
            int productDetailID = int.Parse(Request.Form["slProductDetail"]);

            CartItemData cid = new CartItemData();

            if (cid.AlreadyExistedInCart(cartID, productDetailID))
            {
                ViewBag.Announcement = "Product has already had in cart";
            }
            else
            {
                if (new CartItemData().InsertNewItemToCart(new CartItemDTO {
                    CartId = cartID, ProductDetailId = productDetailID, Quantity = quantity
                }))
                {
                    ViewBag.Announcement = "Add to cart successfully";
                }
                else
                {
                    ViewBag.Announcement = "Add to cart failed";
                }
            }
            ViewBag.Cart = new CartItemData().GetCartItemsByCartID(cartID);
            return(View("Cart"));
        }
コード例 #12
0
        public void UpdateQuantity_Should_Update_Quantity_Of_Item_In_Cart()
        {
            var cartService = new CartService();
            var cartItems   = cartService.GetCartItems();

            Assert.IsTrue(cartItems.Count == 0);

            var item = new Item()
            {
                Id       = 1,
                SKU      = "3",
                Quantity = 100
            };

            cartService.AddToCart(item);
            cartItems = cartService.GetCartItems();

            Assert.AreEqual(1, cartItems.Count);

            item.Quantity = 50;
            cartService.UpdateQuantity(item);

            item = cartService.GetCartItem(item.Id);

            Assert.AreEqual(50, item.Quantity);

            // because of static data, I have had to clean up after each test
            CartData.EmptyCart();
        }
コード例 #13
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();
            CartData cartData = new CartData();

            ListView.ItemsSource = await cartData.GetCartDataAsyncByOrderId(Order_Id);
        }
コード例 #14
0
        public IActionResult RemoveFromCart([FromBody] ProductInCart product)
        {
            //Retrieve userId and SessionId from cookies
            string sessionId = HttpContext.Request.Cookies["sessionId"];
            string userId    = null;

            if (sessionId != null)
            {
                if (HttpContext.Request.Cookies["userId"] != null)
                {
                    userId = HttpContext.Request.Cookies["userId"];
                }
            }

            /*
             * Create a session object to query data since items in the cart can be temporary
             * or permanent based on whether the user has logged in or not.
             * Session object allows to query based on session id or user id based on whether the user
             * has logged in
             */
            Session sess = new Session()
            {
                SessionId = sessionId,
                UserId    = userId
            };

            CartData.DeleteFromCart(product, sess);

            return(Json(new
            {
                success = true
            }));
        }
コード例 #15
0
        public ActionResult AddCart(long productID, int quantity)
        {
            bool exists  = false;
            var  session = (UserLogin)Session[CommonConstants.USER_SESSION];

            if (session == null)
            {
                return(RedirectToAction("Login", "Login", new { area = "" }));
            }
            var list    = new List <CartModel>();
            var cart    = new CartData().GetByUserID(session.userID);
            var product = new ProductData().ListAll();

            foreach (var temp in cart)
            {
                foreach (var item in product)
                {
                    if (temp.ProductID == item.ProductID)
                    {
                        var cartModel = new CartModel();
                        cartModel.CartID   = temp.CartID;
                        cartModel.UserID   = session.userID;
                        cartModel.Product  = item;
                        cartModel.Quantity = temp.Quantity;
                        list.Add(cartModel);
                    }
                }
            }
            foreach (var item in list)
            {
                //Cập nhât hàng hóa đã có sẵn
                if (item.Product.ProductID == productID)
                {
                    item.Quantity = item.Quantity + quantity;
                    var temp = new Cart();
                    temp.CartID    = item.CartID;
                    temp.UserID    = session.userID;
                    temp.ProductID = item.Product.ProductID;
                    temp.Quantity  = item.Quantity;
                    new CartData().Update(temp);
                }
            }
            foreach (var item in list)
            {
                if (item.Product.ProductID == productID)
                {
                    exists = true;
                    break;
                }
            }
            if (exists == false)
            {
                var cartModel = new Cart();
                cartModel.UserID    = session.userID;
                cartModel.ProductID = productID;
                cartModel.Quantity  = quantity;
                new CartData().Insert(cartModel);
            }
            return(Redirect(Request.UrlReferrer.ToString()));
        }
コード例 #16
0
        private static void RecalculateSummary(HttpContext context)
        {
            var objCtrl = new NBrightBuyController();

            var currentcart = new CartData(PortalSettings.Current.PortalId);
            var ajaxInfo    = NBrightBuyUtils.GetAjaxInfo(context, true);
            var shipoption  = currentcart.GetShippingOption(); // ship option already set in address update.

            currentcart.AddExtraInfo(ajaxInfo);
            currentcart.SetShippingOption(shipoption);
            currentcart.PurchaseInfo.SetXmlProperty("genxml/currentcartstage", "cartsummary"); // (Legacy) we need to set this so the cart calcs shipping
            currentcart.PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/radiobuttonlist/shippingprovider", ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider"));

            var shipref     = ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/shippingprovider");
            var displayanme = "";
            var shipInfo    = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SHIPPING", shipref);

            if (shipInfo != null)
            {
                var shipprov = ShippingInterface.Instance(shipref);
                if (shipprov != null)
                {
                    displayanme = shipprov.Name();
                }
            }
            if (displayanme == "")
            {
                displayanme = shipref;
            }
            currentcart.PurchaseInfo.SetXmlProperty("genxml/extrainfo/genxml/hidden/shippingdisplayanme", displayanme);

            currentcart.Lang = ajaxInfo.Lang;  // set lang so we can send emails in same language the order was made in.

            currentcart.Save(StoreSettings.Current.DebugMode, true);
        }
コード例 #17
0
        public ActionResult Add(int ProductId, int?cartId, string sessionId)
        {
            cartId             = CartData.AddtoCart(ProductId, cartId, sessionId);
            TempData["cartId"] = cartId;

            return(RedirectToAction("Index", new { sessionId = sessionId, cartId = cartId }));
        }
コード例 #18
0
        private static string UpdateCartAddress(HttpContext context, String addresstype = "")
        {
            var currentcart = new CartData(PortalSettings.Current.PortalId);
            var ajaxInfo    = NBrightBuyUtils.GetAjaxInfo(context, true);

            currentcart.PurchaseInfo.SetXmlProperty("genxml/currentcartstage", "cartsummary"); // (Legacy) we need to set this so the cart calcs shipping

            if (addresstype == "bill")
            {
                currentcart.AddBillingAddress(ajaxInfo);
                currentcart.Save();
            }

            if (addresstype == "ship")
            {
                currentcart.AddShippingAddress(ajaxInfo);
                currentcart.Save();
            }

            if (addresstype == "shipoption")
            {
                var shipoption = ajaxInfo.GetXmlProperty("genxml/radiobuttonlist/rblshippingoptions");
                currentcart.SetShippingOption(shipoption);
                currentcart.Save();
            }

            return(addresstype);
        }
コード例 #19
0
        public async Task <IActionResult> DeleteFromCartBook(int cartItemId)
        {
            string CartData;

            try
            {
                string userId = null;
                userId = User.FindFirst("userId").Value;
                if (userId == null)
                {
                    return(this.Ok(new ResponseEntity(HttpStatusCode.OK, "Invalid Token", userId, "")));
                }
                CartData = await Task.FromResult(CartService.DeleteFromCartBook(cartItemId));

                if (!CartData.Contains("Not") && CartData != null)
                {
                    return(this.Ok(new ResponseEntity(HttpStatusCode.OK, CartData, cartItemId, "")));
                }
            }
            catch
            {
                return(this.BadRequest(new ResponseEntity(HttpStatusCode.BadRequest, "Bad Request", null, "")));
            }
            return(this.Ok(new ResponseEntity(HttpStatusCode.NoContent, CartData, cartItemId, "")));
        }
コード例 #20
0
        private static void AddAllToBasket(HttpContext context)
        {
            try
            {
                var ajaxInfoList = NBrightBuyUtils.GetAjaxInfoList(context);
                foreach (var ajaxInfo in ajaxInfoList)
                {
                    var settings = ajaxInfo.ToDictionary();

                    if (settings.ContainsKey("productid"))
                    {
                        if (!settings.ContainsKey("portalid"))
                        {
                            settings.Add("portalid", PortalSettings.Current.PortalId.ToString(""));                                    // aways make sure we have portalid in settings
                        }
                        var currentcart = new CartData(Convert.ToInt16(settings["portalid"]));
                        currentcart.AddAjaxItem(ajaxInfo, StoreSettings.Current.SettingsInfo, StoreSettings.Current.DebugMode);
                        currentcart.Save(StoreSettings.Current.DebugMode);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
            }
        }
コード例 #21
0
        public ActionResult CheckOut(int CustomerId)
        {
            int P_ID, Qty;

            //create New Purchase Record
            PurchaseData.CreateNewPurchase(CustomerId);
            foreach (string key in Request.Form.AllKeys)
            {
                //Debug.WriteLine("Keys : : : " + key);
                //Debug.WriteLine("Value : : : " + Request[key]);
                if (key != "CheckOut")
                {
                    P_ID = Convert.ToInt32(key);
                    Qty  = Convert.ToInt32(Request[key]);

                    for (int i = 0; i < Qty; i++)
                    {
                        PurchaseData.InsertNewPurchses(P_ID);
                    }
                }
            }
            //delete form Cart
            CartData.ClearCart(CustomerId);
            Customer customer_data = CustomerData.GetCustomerByCustomerId(CustomerId);
            string   session       = customer_data.SessionId;

            return(RedirectToAction("Index", "Purchases", new { sessionId = @session }));
        }
コード例 #22
0
        public void CreateCartLines()
        {
            CartData.Clear();
            if (CurrentTicket?.CarteLines == null)
            {
                NotifyOfPropertyChange("CartData");
                NotifyOfPropertyChange("Total");

                NotifyOfPropertyChange("CmdStatus");
                NotifyOfPropertyChange("CmdColor");
                return;
            }

            foreach (var cartLine in CurrentTicket?.CarteLines)
            {
                cartLine.ListePrix = CurrentTicket.ListePrix;
                var cartLineView = new CartLineViewModel(cartLine);
                cartLineView.clickEvent  += CartLineView_clickEvent;
                cartLineView.DoubleClick += CartLineView_DoubleClick;
                var view = DataHelpers.container.Get <ViewManager>().CreateAndBindViewForModelIfNecessary(cartLineView);
                CartData.Add(view);
            }


            NotifyOfPropertyChange("CartData");
            NotifyOfPropertyChange("Tickets");
            NotifyOfPropertyChange("Total");
            NotifyOfPropertyChange("CurrentTicket");

            NotifyOfPropertyChange("CmdStatus");
            NotifyOfPropertyChange("CmdColor");
        }
コード例 #23
0
 public void BindItem()
 {
     try
     {
         if (CartData.GetData().Count() > 0)
         {
             this.treeListView1.Roots           = null;
             this.treeListView1.Roots           = CartData.GetData();
             this.treeListView1.CanExpandGetter = x => (x as vmItems).vmChildItems.Count > 0;
             this.treeListView1.ChildrenGetter  = x => (x as vmItems).vmChildItems;
             this.treeListView1.ExpandAll();
             this.treeListView1.TreeColumnRenderer.IsShowLines  = false;
             this.treeListView1.TreeColumnRenderer.IsShowGlyphs = false;
             this.treeListView1.Refresh();
             //this.treeListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
             //this.treeListView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
             //this.treeListView1.UseAlternatingBackColors = true;
             //this.treeListView1.AlternateRowBackColor = Color.FromArgb(224, 224, 224);
         }
         else
         {
             this.treeListView1.Roots = null;
             //this.treeListView1.Rows.Clear();
             //this.treeListView1.Columns.Clear();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #24
0
        /**
         * I wanted to add a better return type for these services,
         * something that had a response and message. But I'm unsure of what that looks like
         */

        public bool AddToCart(Item item)
        {
            // I would make this more generic for anything more than a POC

            var cheese = CheeseData.GetAllCheese().FirstOrDefault(x => x.SKU == item.SKU);

            if (cheese == null)
            {
                return(false);
            }

            // Because of static Cheese data, this copy is needed to give the illution of more than 1 item. This would not be the case in a real app.
            // This felt dirty, I had to shower after this.
            var cartItem = new Cheese()
            {
                Name       = cheese.Name,
                Colour     = cheese.Colour,
                Flavour    = cheese.Flavour,
                Aroma      = cheese.Aroma,
                PictureRef = cheese.PictureRef,
                SKU        = cheese.SKU,
                Texture    = cheese.Texture,
                Price      = cheese.Price,
                Quantity   = item.Quantity,
                Id         = CartData.GetCartItemCount() + 1
            };

            CartData.AddItemToCart(cartItem);
            return(true);
        }
コード例 #25
0
        public static string ProcessCommand(string paramCmd, HttpContext context)
        {
            var strOut   = "ORDER - ERROR!! - No Security rights for current user!";
            var ajaxInfo = NBrightBuyUtils.GetAjaxFields(context);

            switch (paramCmd)
            {
            case "payment_manualpayment":
                strOut = "";
                var cartInfo = new CartData(PortalSettings.Current.PortalId);
                if (cartInfo != null)
                {
                    cartInfo.SaveModelTransQty();     // move qty into trans
                    cartInfo.ConvertToOrder(StoreSettings.Current.DebugMode);
                    var orderData = new OrderData(cartInfo.PurchaseInfo.ItemID);
                    orderData.PaymentProviderKey = ajaxInfo.GetXmlProperty("genxml/hidden/paymentproviderkey").ToLower();     // provider keys should always be lowecase
                    orderData.SavePurchaseData();
                    strOut = PaymentsInterface.Instance(orderData.PaymentProviderKey).RedirectForPayment(orderData);
                }
                break;

            case "payment_getlist":
                strOut = GetPaymentList(context);
                break;
            }

            return(strOut);
        }
コード例 #26
0
        public List <Cheese> GetCartItems()
        {
            var cartItems  = CartData.GetCartItems();
            var returnList = new List <Cheese>();

            foreach (var cartItem in cartItems)
            {
                var cheese = CheeseData.GetAllCheese().FirstOrDefault(x => x.SKU == cartItem.SKU);
                if (cheese == null)
                {
                    continue;
                }
                returnList.Add(new Cheese()
                {
                    Name       = cheese.Name,
                    Aroma      = cheese.Aroma,
                    Colour     = cheese.Colour,
                    Flavour    = cheese.Flavour,
                    PictureRef = cheese.PictureRef,
                    Price      = cheese.Price,
                    SKU        = cheese.SKU,
                    Texture    = cheese.Texture,

                    Id       = cartItem.Id,
                    Quantity = cartItem.Quantity
                });
            }
            return(returnList);
        }
コード例 #27
0
    public ActionResult Checkout(int cartID)
    {
        List <CartItem> items = CartData.GetCartDetailsByCartId(cartID);

        CartData.WriteItemsToPurchase(items, cartID);
        return(View());
    }
コード例 #28
0
        // GET: Cart
        public ActionResult Index()
        {
            var session = (UserLogin)Session[CommonConstants.USER_SESSION];

            if (session == null)
            {
                return(RedirectToAction("Login", "Login", new { area = "" }));
            }
            var list    = new List <CartModel>();
            var cart    = new CartData().GetByUserID(session.userID);
            var product = new ProductData().ListAll();

            foreach (var temp in cart)
            {
                foreach (var item in product)
                {
                    if (temp.ProductID == item.ProductID)
                    {
                        var cartModel = new CartModel();
                        cartModel.CartID   = temp.CartID;
                        cartModel.UserID   = session.userID;
                        cartModel.Product  = item;
                        cartModel.Quantity = temp.Quantity;
                        list.Add(cartModel);
                    }
                }
            }
            return(View(list));
        }
コード例 #29
0
        public ActionResult addCart(int id)
        {
            tbl_Product p       = db.tbl_Product.Find(id);
            CartData    oldCart = (CartData)Session["cart"];

            Session.Remove("cart");
            CartData cart = new CartData(oldCart);

            if (cart.arrCart.Count > 0)
            {
                for (int i = 0; i < cart.arrCart.Count; i++)
                {
                    Cart c = (Cart)cart.arrCart[i];
                    if (c.item.id == id)
                    {
                        if (p.amount > c.amounts)
                        {
                            cart.add(p);
                        }
                        Session["cart"] = cart;
                        return(Redirect(Request.UrlReferrer.AbsoluteUri));
                    }
                }
            }
            cart.add(p);
            Session["cart"] = cart;
            return(Redirect(Request.UrlReferrer.AbsoluteUri));
        }
コード例 #30
0
        public void AddToShoppingCart(int productID)
        {
            var cart = this.GetCart();

            var cartItem = cart.Find(c => c.Product.ProductID == productID);

            if (cartItem != null)
            {
                cartItem.Quantity++;
                cartItem.WeightProducts = (cartItem.WeightProducts + cart.Where(a => a.Product.ProductID == productID).Select(i => i.WeightProducts).Single());
            }
            else
            {
                var AddProduct = db.Products.Where(a => a.ProductID == productID).SingleOrDefault();
                if (AddProduct != null)
                {
                    var newcartData = new CartData()
                    {
                        Product            = AddProduct,
                        Quantity           = 1,
                        TotalPriceProducts = AddProduct.Price,
                        WeightProducts     = AddProduct.Weight
                    };
                    cart.Add(newcartData);
                }
            }
            Session.Set(CartSessionKey, cart);
        }