public void CheckSummaryPage(Table table)
        {
            var expectedSummary = table.CreateInstance <ShoppingCartSummary>();

            ShoppingCartSummary gotSummary = new ShoppingCartSummary();

            IWebElement cartTable = driver.FindElement(By.TagName("tbody"));
            IReadOnlyCollection <IWebElement> rows = cartTable.FindElements(By.TagName("tr"));
            IReadOnlyCollection <IWebElement> cols = null;

            foreach (IWebElement row in rows)
            {
                cols = row.FindElements(By.TagName("td"));
                foreach (IWebElement col in cols)
                {
                    Console.WriteLine(col.Text);
                }
            }

            IWebElement[] array = cols.ToArray();
            gotSummary.Description = array[1].Text;
            Console.WriteLine("Element 0 = " + gotSummary.Description);
            gotSummary.Available = array[2].Text;
            Console.WriteLine("Element 1 = " + gotSummary.Available);
            gotSummary.UnitPrice = array[3].Text;
            Console.WriteLine("Element 2 = " + gotSummary.UnitPrice);

            table.CompareToInstance <ShoppingCartSummary>(gotSummary);
        }
Beispiel #2
0
 public ActionResult Partial()
 {
     using (HotAshContext context = new HotAshContext()) {
         ShoppingCartSummary summary = GetShoppingCartSummary(context);
         return(PartialView("_AjaxCartSummary", summary));
     }
 }
Beispiel #3
0
        public ActionResult AddToCart(int id)
        {
            using (HotAshContext context = new HotAshContext()) {
                Cigar addCigar = context.Cigars.FirstOrDefault(x => x.ID == id);

                if (addCigar != null)
                {
                    var sameItemInCart = context.ShoppingCarts.FirstOrDefault(x => x.Cigar.ID == id && x.UserID == UserID);
                    if (sameItemInCart == null)
                    {
                        ShoppingCart sc = new ShoppingCart {
                            Cigar     = addCigar,
                            UserID    = UserID,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        sameItemInCart.Quantity++;
                    }

                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);
                return(PartialView("_AjaxCartSummary", summary));
            }
        }
Beispiel #4
0
        public ActionResult AddToCart(int id)
        {
            using (RentMyWroxContext context = new RentMyWroxContext())
            {
                Item addedItem = context.Items.FirstOrDefault(x => x.Id == id);

                // now that we know it is a valid ID
                if (addedItem != null)
                {
                    // Check to see if this item was already added
                    var sameItemInShoppingCart = context.ShoppingCarts
                                                 .FirstOrDefault(x => x.Item.Id == id && x.UserId == UserID);
                    if (sameItemInShoppingCart == null)
                    {
                        // if not already in cart then add it
                        ShoppingCart sc = new ShoppingCart
                        {
                            Item      = addedItem,
                            UserId    = UserID,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        // increment the quantity of the existing shopping cart item
                        sameItemInShoppingCart.Quantity++;
                    }
                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);
                return(PartialView("_ShoppingCartSummary", summary));
            }
        }
 public ActionResult Partial()
 {
     using (TicketDominatorContext context = new TicketDominatorContext()) {
         ShoppingCartSummary summary = GetShoppingCartSummary(context);
         return(PartialView("_AjaxCartSummary", summary));
     }
 }
 public ActionResult Index()
 {
     using (RentMyWroxContext context = new RentMyWroxContext())
     {
         ShoppingCartSummary summary = GetShoppingCartSummary(context);
         return(PartialView("_ShoppingCartSummary", summary));
     }
 }
Beispiel #7
0
        private ShoppingCartSummary GetShoppingCartSummary(HotAshContext context)
        {
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var cartList = context.ShoppingCarts.Where(x => x.UserID == UserID);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Cigar.Price);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
Beispiel #8
0
        private ShoppingCartSummary GetShoppingCartSummary(RentMyWroxContext context)
        {
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var cartList = context.ShoppingCarts.Where(x => x.UserId == UserID);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Item.Cost);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
        private ShoppingCartSummary GetShoppingCartSummary(TicketDominatorContext context)
        {
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var cartList = context.ShoppingCarts.Where(x => x.UserId == UserId);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Ticket.Price);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
        public IActionResult Shipping()
        {
            ShoppingCartSummary cartSummary = GetCartSummary();
            ShoppingCartDetail  cartDetails = _shoppingCartProvider.GetDetail(cartSummary.Id);

            if (!cartDetails.RequiresShipping)
            {
                return(RedirectToAction(nameof(Checkout)));
            }

            ShippingModel model = new ShippingModel(GetModelData());

            PrepareShippingAddressModel(in model, _accountProvider.GetDeliveryAddresses(GetUserSession().UserID));

            return(View(model));
        }
        public IActionResult Index()
        {
            List <BasketItemModel> basketItems = new List <BasketItemModel>();
            ShoppingCartSummary    cartSummary = GetCartSummary();
            BasketModel            model;

            BaseModelData modelData = GetModelData();

            if (cartSummary.Id != 0)
            {
                ShoppingCartDetail cartDetails = _shoppingCartProvider.GetDetail(cartSummary.Id);
                _stockProvider.GetStockAvailability(cartDetails.Items);

                foreach (ShoppingCartItem item in cartDetails.Items)
                {
                    basketItems.Add(new BasketItemModel(GetModelData(),
                                                        item.Id, item.Name, item.Description,
                                                        item.Size, item.SKU, item.ItemCost, (int)item.ItemCount,
                                                        item.StockAvailability > 500 ? "> 500" : item.StockAvailability.ToString(),
                                                        item.ItemCount * item.ItemCost, false, item.Images[0]));
                }

                if (TempData.ContainsKey("VoucherError"))
                {
                    ModelState.AddModelError(nameof(VoucherModel.Voucher), Languages.LanguageStrings.VoucherInvalid);
                    TempData.Remove("VoucherError");
                }

                modelData.ReplaceCartSummary(cartSummary);
                model = new BasketModel(modelData, basketItems,
                                        cartDetails.CouponCode, cartDetails.RequiresShipping,
                                        !String.IsNullOrEmpty(GetUserSession().UserEmail));
            }
            else
            {
                modelData.ReplaceCartSummary(cartSummary);
                model = new BasketModel(modelData, new List <BasketItemModel>(),
                                        String.Empty, false, GetUserSession().UserID != 0);
            }

            return(View(model));
        }
        private ShoppingCartSummary GetShoppingCartSummary(RentMyWroxContext context)
        {
            Guid UserID = UserHelper.GetUserId();
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var appUser = UserHelper.GetApplicationUser();

            if (appUser != null)
            {
                summary.UserDisplayName = string.Format("{0} {1}", appUser.FirstName, appUser.LastName);
            }

            var cartList = context.ShoppingCarts.Where(x => x.UserId == UserID);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Item.Cost);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
        public ActionResult AddToCart(int id, bool mobile = false)
        {
            using (TicketDominatorContext context = new TicketDominatorContext())
            {
                Ticket addTicket = context.Tickets.FirstOrDefault(x => x.Id == id);

                if (addTicket != null)
                {
                    var sameItemInCart = context.ShoppingCarts.FirstOrDefault(x => x.Ticket.Id == id && x.UserId == UserId);
                    if (sameItemInCart == null)
                    {
                        ShoppingCart sc = new ShoppingCart
                        {
                            Ticket    = addTicket,
                            UserId    = UserId,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        sameItemInCart.Quantity++;
                    }

                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);

                if (mobile)
                {
                    return(Json(summary, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(PartialView("_AjaxCartSummary", summary));
                }
            }
        }
        private void CreateShopPage()
        {
            var hasCreatedPage = SampleUtilities.CreateLocalizedPage(new Guid(SampleConstants.ShopBasePageId), "TIU Shop", false, true, "en");
            if (hasCreatedPage)
            {
                SampleUtilities.SetTemplateToLocalizedPage(new Guid(SampleConstants.ShopBasePageId), new Guid(SampleConstants.EducationTemplateId), "en");

                // Add page title
                ContentBlockBase pageTitle = new ContentBlockBase();
                pageTitle.Html = "<h1>University shop</h1>";
                SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ShopBasePageId), pageTitle, "content", "Title", "en");

                // Add layout control
                var mainLayoutControl = new LayoutControl();
                var mainLayoutColumns = new List<ColumnDetails>();

                var mainLayoutColumn1 = new ColumnDetails()
                {
                    ColumnSpaces = new ColumnSpaces(0, 15, 0, 0),
                    PlaceholderId = "Left",
                    ColumnWidthPercentage = 75
                };
                mainLayoutColumns.Add(mainLayoutColumn1);

                var mainLayoutColumn2 = new ColumnDetails()
                {
                    ColumnSpaces = new ColumnSpaces(0, 0, 0, 15),
                    PlaceholderId = "Right",
                    ColumnWidthPercentage = 25
                };
                mainLayoutColumns.Add(mainLayoutColumn2);

                mainLayoutControl.Layout = SampleUtilities.GenerateLayoutTemplate(mainLayoutColumns, string.Empty);
                mainLayoutControl.ID = "Main";
                SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ShopBasePageId), mainLayoutControl, "content", "75% + 25% (custom)", "en");

                ProductsView productsList = new ProductsView();
                SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ShopBasePageId), productsList, "Main_Left", "Product list", "en");

                ShoppingCartSummary shoppingCartSummary = new ShoppingCartSummary();

                shoppingCartSummary.CheckoutData = @"{""Id"":""" + SampleConstants.ShopCheckoutPageId + @""",""Title"":""Checkout""}";
                shoppingCartSummary.CheckoutUrl = "~/tiu-shop/checkout";

                shoppingCartSummary.ContinueShoppingData = @"{""Id"":""" + SampleConstants.ShopBasePageId + @""",""Title"":""TIU Shop""}";
                shoppingCartSummary.ContinueShoppingUrl = "~/tiu-shop";

                shoppingCartSummary.ShoppingCartData = @"{""Id"":""" + SampleConstants.ShopShoppingCartPageId + @""",""Title"":""Shopping cart""}";
                shoppingCartSummary.ShoppingCartUrl = "~/tiu-shop/shopping-cart";

                // set the Simple list template!
                shoppingCartSummary.TemplateKey = this.GetShoppingCartSummaryTemplateKey();

                SampleUtilities.AddControlToLocalizedPage(new Guid(SampleConstants.ShopBasePageId), shoppingCartSummary, "Main_Right", "Shopping cart summary", "en");
            }
        }