/// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Cart                cart;
            CartLineItem        cartLineItem;
            List <CartLineItem> cartLineItems;

            if (!ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.SetPartnerCustomerCartWhatIf, CartId)))
            {
                return;
            }

            cart = Partner.Customers[CustomerId].Carts[CartId].GetAsync().GetAwaiter().GetResult();

            cartLineItems = new List <CartLineItem>();

            foreach (PSCartLineItem item in LineItems)
            {
                cartLineItem = new CartLineItem();
                cartLineItem.CopyFrom(item);

                cartLineItems.Add(cartLineItem);
            }

            cart.LineItems = cartLineItems;

            cart = Partner.Customers[CustomerId].Carts[CartId].PutAsync(cart).GetAwaiter().GetResult();

            WriteObject(new PSCart(cart));
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Cart                cart;
            CartLineItem        cartLineItem;
            List <CartLineItem> lineItems;

            try
            {
                if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.AddPartnerCustomerCartLineItemWhatIf, CartId)))
                {
                    cart      = Partner.Customers[CustomerId].Carts[CartId].Get();
                    lineItems = cart.LineItems.ToList();

                    cartLineItem = new CartLineItem();
                    cartLineItem.CopyFrom(LineItem);

                    lineItems.Add(cartLineItem);

                    cart = Partner.Customers[CustomerId].Carts[CartId].Put(cart);

                    WriteObject(new PSCart(cart));
                }
            }
            finally
            {
                cart         = null;
                cartLineItem = null;
                lineItems    = null;
            }
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                Cart cart;
                CartLineItem cartLineItem;
                List <CartLineItem> lineItems;

                if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.AddPartnerCustomerCartLineItemWhatIf, CartId)))
                {
                    IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);

                    cart      = await partner.Customers[CustomerId].Carts[CartId].GetAsync(CancellationToken).ConfigureAwait(false);
                    lineItems = cart.LineItems.ToList();

                    cartLineItem = new CartLineItem();
                    cartLineItem.CopyFrom(LineItem);

                    lineItems.Add(cartLineItem);

                    cart = await partner.Customers[CustomerId].Carts[CartId].PutAsync(cart, CancellationToken).ConfigureAwait(false);

                    WriteObject(new PSCart(cart));
                }
            }, true);
        }
 private void OnLineItemChange(CartLineItems.LineItemChangeType type, CartLineItem lineItem)
 {
     switch (type)
     {
     case CartLineItems.LineItemChangeType.Remove:
         DeletedLineItems.Add(lineItem.ID);
         break;
     }
 }
Exemple #5
0
        public Money GetCartLineItemPrice(CartLineItem cartLineItem)
        {
            //In a real scenario this would retrieve the data from an external system most likely, in order to calculate possible "mængderabat"
            var product = _productRepository.Single(p => p.Variants.Any(e => e.Id == cartLineItem.VariantId), includes: e => e.Variants);
            var variant = product.Variants.Single(v => v.Id == cartLineItem.VariantId);

            var singleItemPrice = variant.Price;

            return(singleItemPrice * cartLineItem.Count);
        }
Exemple #6
0
        /// <summary>
        /// Addtional operations to be performed when cloning an instance of <see cref="CartLineItem" /> to an instance of <see cref="PSCartLineItem" />.
        /// </summary>
        /// <param name="lineItem">An instance of the <see cref="CartLineItem" /> class that will serve as base for this instance.</param>
        private void CloneAdditionalOperations(CartLineItem lineItem)
        {
            if (lineItem.ProvisioningContext == null)
            {
                return;
            }

            foreach (KeyValuePair <string, string> item in lineItem.ProvisioningContext)
            {
                ProvisioningContext.Add(item.Key, item.Value);
            }
        }
Exemple #7
0
        public CartLineItemViewModel Create([NotNull] CartLineItem cartLineItem)
        {
            var variant = _variantRepository.Single(v => v.Id == cartLineItem.VariantId);

            return(new CartLineItemViewModel
            {
                Id = cartLineItem.Id,
                Count = cartLineItem.Count,
                VariantId = cartLineItem.VariantId,
                VariantName = variant.Name
            });
        }
        protected override OrderLineItem ToOrderModel(CartLineItem lineItem)
        {
            var result = base.ToOrderModel(lineItem) as LineItemEx;

            // Next lines just copy OuterId from cart LineItemEx to order LineItemEx
            var cartLineItemEx = lineItem as Core.Models.Cart.LineItemEx;

            if (cartLineItemEx != null)
            {
                result.OuterId = cartLineItemEx.OuterId;
            }
            return(result);
        }
Exemple #9
0
        public IActionResult Index(int id, int?size, int?color)
        {
            Guid         cartID;
            Cart         c;
            CartLineItem i;

            if (Request.Cookies.ContainsKey("cartID") && Guid.TryParse(Request.Cookies["cartID"], out cartID) && _context.Cart.Any(x => x.TrackingNumber == cartID))
            {
                c = _context.Cart
                    .Include(x => x.CartLineItems)
                    .ThenInclude(y => y.ProductConfiguration)
                    .ThenInclude(z => z.Product)
                    .Single(x => x.TrackingNumber == cartID);
            }
            else
            {
                c                = new Cart();
                cartID           = Guid.NewGuid();
                c.TrackingNumber = cartID;
                _context.Cart.Add(c);
            }

            if (User.Identity.IsAuthenticated)
            {
                c.User = _context.Users.Find(User.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier).Value);
            }
            i = c.CartLineItems.FirstOrDefault(x => x.ProductConfiguration.Product.ID == id && x.ProductConfiguration.ColorID == color && x.ProductConfiguration.SizeID == size);
            if (i == null)
            {
                i      = new CartLineItem();
                i.Cart = c;
                i.ProductConfiguration = _context.ProductConfiguration.Single(x => x.Product.ID == id && x.ColorID == color && x.SizeID == size);
                c.CartLineItems.Add(i);
            }
            i.Quantity++;

            _context.SaveChanges();
            Response.Cookies.Append("cartID", c.TrackingNumber.ToString(),
                                    new Microsoft.AspNetCore.Http.CookieOptions
            {
                Expires = DateTime.Now.AddYears(1)
            });



            return(RedirectToAction("Index", "Shipping"));
        }
Exemple #10
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.NewCartWhatIf, CustomerId)))
                {
                    IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);

                    Cart cart;
                    CartLineItem lineItem;
                    List <CartLineItem> lineItems = new List <CartLineItem>();

                    foreach (PSCartLineItem item in LineItems)
                    {
                        lineItem = new CartLineItem
                        {
                            BillingCycle  = item.BillingCycle,
                            CatalogItemId = item.CatalogItemId,
                            CurrencyCode  = item.CurrencyCode,
                            Error         = item.Error,
                            FriendlyName  = item.FriendlyName,
                            Id            = item.Id,
                            OrderGroup    = item.OrderGroup,
                            Participants  = item.Participants,
                            Quantity      = item.Quantity
                        };

                        foreach (KeyValuePair <string, string> kvp in item.ProvisioningContext?.Cast <DictionaryEntry>().ToDictionary(entry => (string)entry.Key, entry => (string)entry.Value))
                        {
                            lineItem.ProvisioningContext.Add(kvp.Key, kvp.Value);
                        }

                        lineItems.Add(lineItem);
                    }

                    cart = new Cart
                    {
                        LineItems = lineItems
                    };

                    cart = await partner.Customers[CustomerId].Carts.CreateAsync(cart, CancellationToken).ConfigureAwait(false);

                    WriteObject(new PSCart(cart));
                }
            }, true);
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Cart                cart;
            CartLineItem        lineItem;
            List <CartLineItem> lineItems;

            if (!ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.NewCartWhatIf, CustomerId)))
            {
                return;
            }

            lineItems = new List <CartLineItem>();

            foreach (PSCartLineItem item in LineItems)
            {
                lineItem = new CartLineItem
                {
                    BillingCycle  = item.BillingCycle,
                    CatalogItemId = item.CatalogItemId,
                    CurrencyCode  = item.CurrencyCode,
                    Error         = item.Error,
                    FriendlyName  = item.FriendlyName,
                    Id            = item.Id,
                    OrderGroup    = item.OrderGroup,
                    Participants  = item.Participants,
                    Quantity      = item.Quantity
                };

                foreach (KeyValuePair <string, string> kvp in item.ProvisioningContext?.Cast <DictionaryEntry>().ToDictionary(entry => (string)entry.Key, entry => (string)entry.Value))
                {
                    lineItem.ProvisioningContext.Add(kvp.Key, kvp.Value);
                }

                lineItems.Add(lineItem);
            }

            cart = new Cart
            {
                LineItems = lineItems
            };

            cart = Partner.Customers[CustomerId].Carts.CreateAsync(cart).GetAwaiter().GetResult();

            WriteObject(new PSCart(cart));
        }
Exemple #12
0
 public ActionResult Order(CartLineItem cart)
 {
     if (ModelState.IsValid)
     {
         try
         {
             dbcon = GetConnection();
             dbcon.Open();
             //cart.CartNumber = 100;
             // if no cart number exists
             if (Session["cartnumber"] == null)
             {
                 Session["cartnumber"] = Utility.GetIdNumber(dbcon, "CartNumber");
             }
             cart.CartNumber = Convert.ToInt32(Session["cartnumber"].ToString());
             int intresult = CartLineItem.CartUpSert(dbcon, cart);
             dbcon.Close();
         } catch (Exception ex) { throw new Exception(ex.Message); }
     }
     return(RedirectToAction("cart"));
 }
Exemple #13
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Cart                cart;
            CartLineItem        cartLineItem;
            List <CartLineItem> lineItems;

            if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.AddPartnerCustomerCartLineItemWhatIf, CartId)))
            {
                cart      = Partner.Customers[CustomerId].Carts[CartId].GetAsync().ConfigureAwait(false).GetAwaiter().GetResult();
                lineItems = cart.LineItems.ToList();

                cartLineItem = new CartLineItem();
                cartLineItem.CopyFrom(LineItem);

                lineItems.Add(cartLineItem);

                cart = Partner.Customers[CustomerId].Carts[CartId].PutAsync(cart).GetAwaiter().GetResult();

                WriteObject(new PSCart(cart));
            }
        }
Exemple #14
0
        public void OrderSuccessfullyPlacedFromNonEmptyCart()
        {
            //Arrange
            var cart          = new Cart(Guid.NewGuid(), Guid.NewGuid());
            var variant1      = new Variant("TestVariant1", Guid.NewGuid(), "Test Variant 1", new Money(Currency.Dkk, 10));
            var variant2      = new Variant("TestVariant2", Guid.NewGuid(), "Test Variant 2", new Money(Currency.Dkk, 20));
            var cartLineItem1 = new CartLineItem(Guid.NewGuid(), cart.Id, variant1, 2);

            cart.CartLineItems.Add(cartLineItem1);
            var cartLineItem2 = new CartLineItem(Guid.NewGuid(), cart.Id, variant2, 3);

            cart.CartLineItems.Add(cartLineItem2);

            var cartRepoMock     = new Mock <ICartRepository>();
            var orderRepoMock    = new Mock <IOrderRepository>();
            var priceServiceMock = new Mock <IPriceService>();

            priceServiceMock.Setup(service => service.GetCartLineItemPrice(cartLineItem1)).Returns(new Money(Currency.Dkk, 20));
            priceServiceMock.Setup(service => service.GetCartLineItemPrice(cartLineItem2)).Returns(new Money(Currency.Dkk, 60));
            priceServiceMock.Setup(service => service.GetTotalCartPrice(cart)).Returns(new Money(Currency.Dkk, 80));
            var orderService = new OrderService(cartRepoMock.Object, orderRepoMock.Object, priceServiceMock.Object);

            //Act
            var order = orderService.PlaceOrder(cart);

            //Assert
            Assert.AreEqual(cart.CustomerId, order.CustomerId);
            Assert.AreEqual(new Money(Currency.Dkk, 80), order.Total);
            Assert.AreEqual(cart.CartLineItems.Count, order.OrderLineItems.Count);
            foreach (var cartLineItem in cart.CartLineItems)
            {
                var matchingOrderLineItem = order.OrderLineItems.Single(cli => cli.VariantId == cartLineItem.VariantId);
                Assert.IsNotNull(matchingOrderLineItem);
                Assert.AreEqual(cartLineItem.Count, matchingOrderLineItem.Count);
            }

            _placedEventHandlerMock.Verify(e => e.Handle(It.IsAny <OrderPlacedEvent>()), Times.Once);
            _cancelledEventHandlerMock.Verify(e => e.Handle(It.IsAny <OrderCancelledEvent>()), Times.Never);
        }
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            CartLineItem lineItem;

            try
            {
                if (!ShouldProcess(Resources.NewPartnerCustomerCartLineItemWhatIf))
                {
                    return;
                }

                lineItem = new CartLineItem
                {
                    CatalogItemId       = CatalogItemId,
                    BillingCycle        = BillingCycle,
                    CurrencyCode        = CurrencyCode,
                    FriendlyName        = FriendlyName,
                    OrderGroup          = OrderGroup,
                    ProvisioningContext = new Dictionary <string, string>(),
                    Quantity            = Quantity
                };

                if (ProvisioningContext != null)
                {
                    foreach (KeyValuePair <object, object> value in ProvisioningContext.Cast <DictionaryEntry>()
                             .ToDictionary(d => d.Key, d => d.Value))
                    {
                        lineItem.ProvisioningContext.Add(value.Key.ToString(), value.Value.ToString());
                    }
                }

                WriteObject(new PSCartLineItem(lineItem));
            }
            finally
            {
                lineItem = null;
            }
        }
        public async Task <IActionResult> CreateShoppingCartItems([FromBody] ShoppingCartCreateDto touristRoute)
        {
            //1. 先获取用户登录ID信息
            var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            //2.(判断用户是否存,这个jwt框架帮你做过了)  获取用户购物车
            var shoppingCart = await repository.GetShoopingCartByUserIdAsync(userId);

            if (shoppingCart == null)
            {
                return(NotFound($"用户{userId}的购物车不存在"));
            }
            //3.获取旅游路线信息
            var tourist = await repository.GetTouristRoutAsync(touristRoute.TouristRouteID);

            if (tourist == null)
            {
                return(NotFound($"旅游线路{touristRoute.TouristRouteID}不存在"));
            }

            CartLineItem lineItems = new CartLineItem()
            {
                OriginalPrice   = tourist.OriginalPrice,
                DiscountPresent = tourist.DiscountPresent,
                ShoppingCartId  = shoppingCart.Id,
                TouristID       = tourist.ID,
                TouristRout     = tourist,
            };
            //5. 异步调用上下文添加
            await repository.AddCartLineItemAsync(lineItems);

            //6.保存
            await repository.SaveAsync();

            //7. 返回
            return(Ok(mapper.Map <ShoppingCartDto>(shoppingCart)));
        }
Exemple #17
0
        public ActionResult Cart(FormCollection fc)
        {
            try
            {
                // Validate
                if (!Valid_CartData(fc))
                {
                    throw new Exception("Cart data invalid");
                }

                int intresult = 0;
                // string cartid = 0;
                // int rowid = Convert.ToInt32(fc["rowid"].ToString());
                // string strprodid = fc["prod:" + rowid].ToString();
                // int cartid = 100;

                string straction = fc["action"].ToString();
                string cartid    = fc["cartid"].ToString();
                string prodid    = fc["prodid"].ToString();
                string strqty    = fc["qty"].ToString();

                if (Session["cartnumber"] != null)
                {
                    cartid = Session["cartnumber"].ToString();
                }

                dbcon = GetConnection();
                dbcon.Open();
                CartLineItem.CUDCart(dbcon, straction, Int32.Parse(cartid), prodid, Int32.Parse(strqty));
                dbcon.Close();
                return(RedirectToAction("Cart"));
            } catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PSCartLineItem" /> class.
 /// </summary>
 /// <param name="lineItem">An instance of the <see cref="CartLineItem" /> class that will serve as a base for this instance.</param>
 public PSCartLineItem(CartLineItem lineItem)
 {
     ProvisioningContext = new Dictionary <string, string>();
     this.CopyFrom(lineItem, CloneAdditionalOperations);
 }
 public void DeleteLineItem(CartLineItem item)
 {
     FakeContext.CartLineItems.Remove(item);
 }
 public async Task AddCartLineItemAsync(CartLineItem cartLineItem)
 {
     await FakeContext.CartLineItems.AddAsync(cartLineItem);
 }
Exemple #21
0
 public OrderLineItem(Guid id, CartLineItem cartLineItem, Money price) : base(id)
 {
     VariantId = cartLineItem.VariantId;
     Count     = cartLineItem.Count;
     LineTotal = price;
 }
Exemple #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PSCartLineItem" /> class.
 /// </summary>
 /// <param name="lineItem">An instance of the <see cref="CartLineItem" /> class that will serve as a base for this instance.</param>
 public PSCartLineItem(CartLineItem lineItem)
 {
     ProvisioningContext = new Hashtable();
     this.CopyFrom(lineItem, CloneAdditionalOperations);
 }