public async Task Return_ShoppingCartItem_When_Correct_Carameters_Are_Passed()
        {
            var userId           = "a";
            var mockShoppingCart = ShoppingCardMock
                                   .GetMockShoppingCart(userId)
                                   .ShoppingCartItems.ToList()
                                   .FirstOrDefault();

            var userShoppingCartItem = new UserShoppingCartItem()
            {
                ShoppingCartItem = mockShoppingCart,
                UserId           = userId
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <UserShoppingCartItem>(It.IsAny <string>(), It.IsAny <UserShoppingCartItem>(), It.IsAny <string>()))
            .Returns(Task.FromResult <UserShoppingCartItem>(userShoppingCartItem));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            var shoppingCartOrderResult = await shoppingCartDataService.AddShoppingCartItem(mockShoppingCart, userId);

            Assert.NotNull(shoppingCartOrderResult);
            Assert.AreEqual(shoppingCartOrderResult.UserId, userId);
            Assert.NotNull(shoppingCartOrderResult.ShoppingCartItem);
        }
Пример #2
0
        private void ShoppingBag()
        {
            if (Session != null)
            {
                var shippingCost         = Convert.ToDecimal(ConfigurationManager.AppSettings["shippingcost"]);
                var expressshippingCost  = Convert.ToDecimal(ConfigurationManager.AppSettings["expressshippingcost"]);
                var shippingOnPrice      = Convert.ToDecimal(ConfigurationManager.AppSettings["shippingOnPrice"]);
                var currentUserCartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID);
                if (currentUserCartItems != null)
                {
                    var totalPrice = currentUserCartItems.Sum(c => c.Quantity * c.UnitPrice);

                    if (Session["ExpressShip"] != null && Session["ExpressShip"].Equals(true))
                    {
                        Session["ShippingCost"] = totalPrice < shippingOnPrice ? expressshippingCost : shippingCost;
                    }
                    else if (Session["ExpressShip"] != null && Session["ExpressShip"].Equals(false))
                    {
                        Session["ShippingCost"] = totalPrice < shippingOnPrice ? shippingCost : 0;
                    }
                    else
                    {
                        Session["ShippingCost"] = Session["ShippingCost"] != null ? shippingCost : 0;
                    }

                    ViewBag.CartTotalPrice = totalPrice;
                    ViewBag.Cart           = currentUserCartItems; ViewBag.CartUnits = currentUserCartItems.Count();
                }
            }
        }
Пример #3
0
        private void addToCart(SelectedItem item)
        {
            // check if product is valid
            var product = new ProductService().GetById(item.ProductId);

            if (product != null && product.UnitsInStock > 0)
            {
                // check if product already existed
                CartItem cart = new ShoppingCartDataService().GetByProductId(Session.SessionID, item.ProductId);
                if (cart != null)
                {
                    cart.Quantity++;
                    new ShoppingCartDataService().UpdateCartItemQuantity(Session.SessionID, product.ProductId, item.Quantity);
                }
                else
                {
                    var cartItem = new CartItem
                    {
                        PName         = product.PName,
                        ProductId     = product.ProductId,
                        UnitPrice     = product.UnitPrice,
                        Quantity      = item.Quantity,
                        UserSessionId = Session.SessionID
                    };
                    new ShoppingCartDataService().AddCartItem(cartItem);
                }

                product.UnitsInStock--;
            }
        }
Пример #4
0
 public BaseController()
 {
     if (Session != null)
     {
         var currentUserCartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID);
         ViewBag.CartTotalPrice = currentUserCartItems.Sum(c => c.Quantity * c.UnitPrice);
         ViewBag.Cart           = currentUserCartItems;
         ViewBag.CartUnits      = currentUserCartItems.Count();
     }
 }
        public ActionResult Buy(TicketWedstrijd ticketWedstrijd)
        {
            try
            {
                ticketService           = new TicketService();
                bezoekerService         = new BezoekerService();
                bestellingService       = new BestellingService();
                shoppingCartDataService = new ShoppingCartDataService();

                string user = User.Identity.GetUserId();

                // Bestelling toevoegen indien nodig
                Bestelling bestelling = bestellingService.FindOpenstaandeBestellingDoorUser(user);
                int        bestellingId;

                if (bestelling != null)
                {
                    // toevoegen aan bestaande bestelling
                    bestellingId = bestelling.id;
                }
                else
                {
                    // nieuwe bestelling aanmaken
                    bestellingId = bestellingService.CreateNieuweBestelling(0, user);
                }

                // Bezoeker toevoegen indien nodig
                if (bezoekerService.FindBezoeker(ticketWedstrijd.Bezoeker.rijksregisternummer) == null)
                {
                    bezoekerService.AddBezoeker(ticketWedstrijd.Bezoeker);
                }

                try
                {
                    // Ticket toevoegen
                    Ticket ticket = ticketService.BuyTicket(bestellingId, ticketWedstrijd.SelectedVak, ticketWedstrijd.Stadion.id, ticketWedstrijd.Wedstrijd.id, user, ticketWedstrijd.Bezoeker.rijksregisternummer);

                    // nieuwe ShoppingCartData toevoegen indien mogelijk
                    shoppingCartDataService.AddShoppingCartData(user, ticket, bestellingId, ticketWedstrijd.Wedstrijd.id);
                }
                catch (TeveelTicketsException ex)
                {
                    return(View("TeveelTickets"));
                }



                return(RedirectToAction("Success"));
            }
            catch
            {
                return(View("Fail"));
            }
        }
Пример #6
0
 private void ShoppingBag()
 {
     if (Session != null)
     {
         var currentUserCartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID);
         if (currentUserCartItems != null)
         {
             ViewBag.CartTotalPrice = currentUserCartItems.Sum(c => c.Quantity * c.UnitPrice);
             ViewBag.Cart           = currentUserCartItems;
             ViewBag.CartUnits      = currentUserCartItems.Count();
         }
     }
 }
Пример #7
0
        public JsonResult UpdateTotal()
        {
            decimal total;

            try
            {
                var cartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID);
                total = cartItems.Select(p => p.UnitPrice * p.Quantity).Sum();
            }
            catch (Exception) { total = 0; }

            return(Json(new { d = String.Format("{0:c}", total) }, JsonRequestBehavior.AllowGet));
        }
Пример #8
0
        public void Throws_When_Invalid_UserId_Is_Passed(string userId)
        {
            var mockShoppingCart = ShoppingCardMock.GetMockShoppingCart(userId);

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.GetAsync <ShoppingCart>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <ShoppingCart>(mockShoppingCart));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            Assert.ThrowsAsync <ShoppingCartDataServiceException>(
                async() => await shoppingCartDataService.GetShoppingCart(userId));
        }
Пример #9
0
        // GET: ShoppingCart
        public ActionResult Index()
        {
            shoppingCartDataService = new ShoppingCartDataService();
            bestellingService       = new BestellingService();
            Bestelling bestelling = bestellingService.GetBestellingMetTicketsByUser(User.Identity.GetUserId());

            // ViewModel opvullen
            ShoppingCart shoppingCart = new ShoppingCart();

            shoppingCart.Bestelling        = bestelling;
            shoppingCart.ShoppingCartItems = bestelling.ShoppingCartDatas;
            shoppingCart.Tickets           = bestelling.Tickets;
            shoppingCart.TotaalPrijs       = shoppingCartDataService.berekenTotaalPrijs(bestelling);

            return(View(shoppingCart));
        }
Пример #10
0
        // GET: Checkout
        public ActionResult Index()
        {
            if (Session["ExpressShip"] == null)
            {
                Session["ExpressShip"] = false;
            }

            ShoppingBag();
            var currentUserCartItems = new ShoppingCartDataService().GetCurrentUserCartItems(Session.SessionID);

            ViewBag.Cart = currentUserCartItems;
            decimal total = 0;

            if (currentUserCartItems != null && currentUserCartItems.Any())
            {
                total = currentUserCartItems.Select(p => p.UnitPrice * p.Quantity).Sum();
            }
            ViewBag.CartTotalPrice = total;
            return(View());
        }
Пример #11
0
        public async Task Return_ShoppingCart_When_Correct_Carameters_Are_Passed()
        {
            var userId           = "a";
            var mockShoppingCart = ShoppingCardMock.GetMockShoppingCart(userId);

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.GetAsync <ShoppingCart>(It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Task.FromResult <ShoppingCart>(mockShoppingCart));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            var addedOrderResult = await shoppingCartDataService.GetShoppingCart(userId);

            Assert.NotNull(addedOrderResult);
            Assert.AreEqual(addedOrderResult.ShoppingCartId, mockShoppingCart.ShoppingCartId);
            Assert.AreEqual(addedOrderResult.UserId, mockShoppingCart.UserId);
            Assert.NotNull(addedOrderResult.ShoppingCartItems);
            Assert.AreEqual(addedOrderResult.ShoppingCartItems.ToList().Count, 1);
        }
        public void Throws_When_ShoppingCartItem_Is_Null()
        {
            var userId = "a";
            ShoppingCartItem shoppingItem = null;

            var userShoppingCartItem = new UserShoppingCartItem()
            {
                ShoppingCartItem = shoppingItem,
                UserId           = userId
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <UserShoppingCartItem>(It.IsAny <string>(), It.IsAny <UserShoppingCartItem>(), It.IsAny <string>()))
            .Returns(Task.FromResult <UserShoppingCartItem>(userShoppingCartItem));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            Assert.ThrowsAsync <ShoppingCartDataServiceException>(
                async() => await shoppingCartDataService.AddShoppingCartItem(shoppingItem, userId));
        }
Пример #13
0
        public ActionResult QuanityChange(int type, int pId)
        {
            var product = new ShoppingCartDataService().GetByProductId(Session.SessionID, pId);

            if (product == null)
            {
                return(Json(new { d = "0" }));
            }

            var actualProduct = new ProductService().GetById(pId);
            int quantity;

            switch (type)
            {
            case 0:
                product.Quantity--;
                actualProduct.UnitsInStock++;
                new ShoppingCartDataService().ExecuteChangeInQuantity(Session.SessionID, pId, "-");
                break;

            case 1:
                product.Quantity++;
                actualProduct.UnitsInStock--;
                new ShoppingCartDataService().ExecuteChangeInQuantity(Session.SessionID, pId, "+");
                break;

            case -1:
                actualProduct.UnitsInStock += product.Quantity;
                product.Quantity            = 0;
                new ShoppingCartDataService().ExecuteChangeInQuantity(Session.SessionID, pId, "x");
                break;

            default:
                return(Json(new { d = "0" }));
            }

            return(RedirectToAction("Index"));
        }
        public void Throws_When_Invalid_UserId_Is_Passed(string userId)
        {
            var mockShoppingCart = ShoppingCardMock
                                   .GetMockShoppingCart(userId)
                                   .ShoppingCartItems.ToList()
                                   .FirstOrDefault();

            var userShoppingCartItem = new UserShoppingCartItem()
            {
                ShoppingCartItem = mockShoppingCart,
                UserId           = userId
            };

            var requestProviderMock = new Mock <IRequestProvider>();

            requestProviderMock
            .Setup(e => e.PostAsync <UserShoppingCartItem>(It.IsAny <string>(), It.IsAny <UserShoppingCartItem>(), It.IsAny <string>()))
            .Returns(Task.FromResult <UserShoppingCartItem>(userShoppingCartItem));

            var shoppingCartDataService = new ShoppingCartDataService(requestProviderMock.Object);

            Assert.ThrowsAsync <ShoppingCartDataServiceException>(
                async() => await shoppingCartDataService.AddShoppingCartItem(mockShoppingCart, userId));
        }
 public ShoppingCartServicelmpl(ShoppingCartDataService shoppingCartDataService)
 {
     _shoppingCartDataService = shoppingCartDataService;
 }
Пример #16
0
 public ActionResult Remove(int id)
 {
     shoppingCartDataService = new ShoppingCartDataService();
     shoppingCartDataService.RemoveShoppingCartData(id);
     return(RedirectToAction("Index"));
 }