public ImmutableList <CheckoutItemDto> GetCheckoutList()
        {
            var cookieHandler = new BasketCookie(_cookiesIn);
            var service       = new CheckoutCookieService(cookieHandler.GetValue());

            return(GetCheckoutList(service.LineItems));
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------
        //private methods

        private string GetUserId(HttpContext httpContext)
        {
            var checkoutCookie = new CheckoutCookie(httpContext.Request.Cookies, httpContext.Response.Cookies);
            var cookieService  = new CheckoutCookieService(checkoutCookie.GetValue());

            return(cookieService.UserId);
        }
Exemplo n.º 3
0
        public void RemoveLineEncodeDecode()
        {
            //SETUP
            var service = new CheckoutCookieService((string)null);

            service.AddLineItem(new OrderLineItem {
                BookId = 1, NumBooks = 4
            });
            service.AddLineItem(new OrderLineItem {
                BookId = 2, NumBooks = 5
            });
            service.AddLineItem(new OrderLineItem {
                BookId = 3, NumBooks = 6
            });

            //ATTEMPT
            service.DeleteLineItem(1);

            //VERIFY
            service.LineItems.Count.ShouldEqual(2);
            service.LineItems[0].BookId.ShouldEqual(1);
            service.LineItems[0].NumBooks.ShouldEqual((short)4);
            service.LineItems[1].BookId.ShouldEqual(3);
            service.LineItems[1].NumBooks.ShouldEqual((short)6);
        }
Exemplo n.º 4
0
        private void ClearCheckoutCookie(HttpContext httpContext)
        {
            var checkoutCookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies);
            var cookieService  = new CheckoutCookieService(checkoutCookie.GetValue());

            cookieService.ClearAllLineItems();
            checkoutCookie.AddOrUpdateCookie(cookieService.EncodeForCookie());
        }
Exemplo n.º 5
0
        /// <summary>
        /// This lists existing orders
        /// </summary>
        /// <returns></returns>
        public List <OrderListDto> GetUsersOrders(IRequestCookieCollection cookiesIn)
        {
            var cookie  = new CheckoutCookie(cookiesIn);
            var service = new CheckoutCookieService(cookie.GetValue());

            return(SelectQuery(_context.Orders.OrderByDescending(x => x.DateOrderedUtc)
                               .Where(x => x.CustomerName == service.UserId)).ToList());
        }
Exemplo n.º 6
0
        public IList <OrderListDto> GetUsersOrders(IRequestCookieCollection cookiesIn)
        {
            var checkoutCookieService = new CheckoutCookieService(cookiesIn);
            var userId = checkoutCookieService.UserId;
            var orders = dataContext.Orders.Where(order => order.CustomerName == userId).OrderByDescending(order => order.DateOrderedUtc);

            return(Select(orders).ToList());
        }
Exemplo n.º 7
0
        public IActionResult AddToCart(OrderLineItem itemToBuy)
        {
            var cookie  = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies);
            var service = new CheckoutCookieService(cookie.GetValue());

            service.AddLineItem(itemToBuy);
            cookie.AddOrUpdateCookie(service.EncodeForCookie());
            return(RedirectToAction("Index"));
        }
        public IActionResult ChooseCustomer(Guid customerKey)
        {
            var cookie  = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies);
            var service = new CheckoutCookieService(cookie.GetValue());

            service.AddCustomer(customerKey);
            cookie.AddOrUpdateCookie(service.EncodeForCookie());
            return(RedirectToAction("Index", "Items"));
        }
Exemplo n.º 9
0
        public IActionResult Buy(OrderItem itemToBuy)
        {
            var cookie  = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); //create a new cookie
            var service = new CheckoutCookieService(cookie.GetValue());                                  //create a new List of OrderLineItem and add the items in the existing cookie to it

            service.AddLineItem(itemToBuy);                                                              //add itemto Buy to the List of OrderLineitems
            cookie.AddOrUpdateCookie(service.EncodeForCookie());                                         //update cookie

            return(RedirectToAction("Index"));
        }
Exemplo n.º 10
0
        public IActionResult DeleteLineItem(int lineNum)
        {
            var cookie  = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies);
            var service = new CheckoutCookieService(cookie.GetValue());

            service.DeleteLineItem(lineNum);
            cookie.AddOrUpdateCookie(service.EncodeForCookie());
            SetupTraceInfo();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public RedirectToActionResult ChooseItems(OrderLineItemDto modifiedDto)
        {
            var listService = new ListItemServices(_context);
            var cookie      = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies);
            var service     = new CheckoutCookieService(cookie.GetValue());

            service.AddLineItem(modifiedDto.RetriveOrderLineItemDto());
            cookie.AddOrUpdateCookie(service.EncodeForCookie());
            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
        public void CreateNewCookie()
        {
            //SETUP

            //ATTEMPT
            var service = new CheckoutCookieService((string)null);

            //VERIFY
            service.UserId.ShouldNotEqual(Guid.Empty);
            service.LineItems.Count.ShouldEqual(0);
        }
Exemplo n.º 13
0
        public IActionResult Buy(OrderLineItem itemToBuy)
        {
            var cookie  = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies);
            var service = new CheckoutCookieService(cookie.GetValue());

            service.AddLineItem(itemToBuy);
            cookie.AddOrUpdateCookie(service.EncodeForCookie());

            SetupTraceInfo();
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 14
0
        public void EncodeDecodeNewCookie()
        {
            //SETUP
            var service = new CheckoutCookieService((string)null);
            var cString = service.EncodeForCookie();
            var userId  = service.UserId;

            //ATTEMPT
            service = new CheckoutCookieService(cString);

            //VERIFY
            service.UserId.ShouldEqual(userId);
            service.LineItems.Count.ShouldEqual(0);
        }
Exemplo n.º 15
0
        public IActionResult Buy(OrderLineItem itemToBuy)
        {
            var cookie = new BasketCookie(
                HttpContext.Request.Cookies,
                HttpContext.Response.Cookies);
            var service = new CheckoutCookieService(cookie.GetValue());

            service.AddLineItem(itemToBuy);
            var cookieOutString = service.EncodeForCookie();

            cookie.AddOrUpdateCookie(cookieOutString);
            SetupTraceInfo(); //Remove this when shown in book listing
            return(RedirectToAction("Index"));
        }
Exemplo n.º 16
0
        public int PlaceOrder(bool acceptTAndCs)
        {
            var checkoutService = new CheckoutCookieService(checkoutCookie.GetValue());
            var placeOrderInDto = new PlaceOrderInDto(acceptTAndCs, checkoutService.UserId, checkoutService.LineItems);
            var order           = runner.RunAction(placeOrderInDto);

            if (runner.HasErrors)
            {
                return(0);
            }

            checkoutService.ClearAllLineItems();
            checkoutCookie.AddOrUpdateCookie(checkoutService.EncodeForCookie());

            return(order.OrderId);
        }
Exemplo n.º 17
0
        public void AddLineItemEncodeDecode()
        {
            //SETUP
            var service = new CheckoutCookieService((string)null);

            service.AddLineItem(new OrderLineItem {
                BookId = 123, NumBooks = 456
            });
            var cString = service.EncodeForCookie();

            //ATTEMPT
            service = new CheckoutCookieService(cString);

            //VERIFY
            service.LineItems.Count.ShouldEqual(1);
            service.LineItems[0].BookId.ShouldEqual(123);
            service.LineItems[0].NumBooks.ShouldEqual((short)456);
        }
        }                                                               //#A

        public Guid GetUserId()
        {
            var httpContext = _httpAccessor.HttpContext;                //#B

            if (httpContext == null)                                    //#B
            {
                return(Guid.Empty);                                     //#B
            }
            var cookie = new BasketCookie(httpContext.Request.Cookies); //#C

            if (!cookie.Exists())                                       //#C
            {
                return(Guid.Empty);                                     //#C
            }
            var service = new CheckoutCookieService(cookie.GetValue()); //#D

            return(service.UserId);                                     //#D
        }
Exemplo n.º 19
0
        /// <summary>
        /// This creates the order and, if successful clears the cookie
        /// </summary>
        /// <returns>Returns the OrderId, or zero if errors</returns>
        public int PlaceOrder(bool acceptTAndCs)
        {
            var checkoutService = new CheckoutCookieService(
                _basketCookie.GetValue());

            var order = _runner.RunAction(
                new PlaceOrderInDto(acceptTAndCs,
                                    checkoutService.UserId, checkoutService.LineItems));

            if (_runner.HasErrors)
            {
                return(0);
            }

            //successful so clear the cookie line items
            checkoutService.ClearAllLineItems();
            _basketCookie.AddOrUpdateCookie(
                checkoutService.EncodeForCookie());

            return(order.OrderId);
        }
Exemplo n.º 20
0
        /// <summary>
        /// This creates the order and, if successful clears the cookie
        /// </summary>
        /// <returns>Returns the OrderId, or zero if errors</returns>
        public int PlaceOrder(bool acceptTAndCs)                 //#G
        {
            var checkoutService = new CheckoutCookieService(     //#H
                _checkoutCookie.GetValue());                     //#H

            var order = _runner.RunAction(                       //#I
                new PlaceOrderInDto(acceptTAndCs,                //#I
                                    checkoutService.UserId,      //#I
                                    checkoutService.LineItems)); //#I

            if (_runner.HasErrors)
            {
                return(0);                   //#J
            }
            //successful so clear the cookie line items
            checkoutService.ClearAllLineItems();    //#K
            _checkoutCookie.AddOrUpdateCookie(      //#K
                checkoutService.EncodeForCookie()); //#K

            return(order.OrderId);                  //#L
        }
Exemplo n.º 21
0
        /// <summary>
        /// This creates the order and, if successful clears the cookie
        /// </summary>
        /// <returns>Returns the OrderId, or zero if errors</returns>
        public async Task <IStatusGeneric <int> > PlaceOrderAndClearBasketAsync(bool acceptTAndCs)
        {
            var status = new StatusGenericHandler <int>();

            var checkoutService = new CheckoutCookieService(
                _basketCookie.GetValue());

            var bizStatus = await _placeOrder.CreateOrderAndSaveAsync(
                new PlaceOrderInDto(acceptTAndCs, checkoutService.UserId, checkoutService.LineItems));


            if (status.CombineStatuses(bizStatus).HasErrors)
            {
                return(status);
            }

            //successful so clear the cookie line items
            checkoutService.ClearAllLineItems();
            _basketCookie.AddOrUpdateCookie(
                checkoutService.EncodeForCookie());

            return(status.SetResult(bizStatus.Result.OrderId));
        }