コード例 #1
0
        // GET: /Cart/Add
        public ActionResult Add(Guid id)
        {
            var cartId = GetCartId();

            var createNewCart = cartId == Guid.Empty;

            CartSummaryViewModel summaryModel;

            if (createNewCart == false)
            {
                var editCartRequest = new EditCartRequest();

                editCartRequest.ItemsToAdd.Add(id);

                editCartRequest.Id = cartId;

                try
                {
                    var editCartResponse = _cartService.EditCart(editCartRequest);

                    summaryModel = editCartResponse.Cart.ConvertToCartSummaryViewModel();

                    SaveCartSummaryToCookie(summaryModel.NumberOfItems, summaryModel.CartTotal.ToString(CultureInfo.InvariantCulture));
                }
                catch (CartDoesNotExistException)
                {
                    createNewCart = true;
                }
            }

            if (!createNewCart) { return RedirectToLocal("/Cart"); }

            var createCartRequest = new CreateCartRequest();

            createCartRequest.AlbumsToAdd.Add(id);

            var response = _cartService.CreateCart(createCartRequest);

            SaveCartIdToCookie(response.Cart.Id);

            summaryModel = response.Cart.ConvertToCartSummaryViewModel();

            SaveCartSummaryToCookie(summaryModel.NumberOfItems, summaryModel.CartTotal.ToString(CultureInfo.InvariantCulture));

            return RedirectToLocal("/Cart");
        }
コード例 #2
0
        public CreateCartResponse CreateCart(CreateCartRequest request)
        {
            var response = new CreateCartResponse();

            var cart = new Cart();

            AddAlbumsToCart(request.AlbumsToAdd, cart);

            ThrowExceptionIfCartIsInvalid(cart);

            _cartRepository.Add(cart);

            _uow.Commit();

            response.Cart = cart.ConvertToCartView();

            return response;
        }