コード例 #1
0
        public void IncrementCartItemQuantityOnce()
        {
            var cartItem = CartItem.Create(_testUnitPrice, _testQuantity, _testCatalogItemId);

            cartItem.IncrementQuantity();

            Assert.Equal(2, cartItem.Quantity);
        }
コード例 #2
0
ファイル: UpdateQuantity.cs プロジェクト: maikeulb/RolleiShop
        public void UpdateCartItemQuantity()
        {
            var cartItem = CartItem.Create(_testUnitPrice, _testQuantity, _testCatalogItemId);

            cartItem.UpdateQuantity(_testNewQuantity);

            Assert.Equal(_testNewQuantity, cartItem.Quantity);
        }
コード例 #3
0
        public void CanCreateRevisitedCartWithExistingItems()
        {
            var cart = RevisitedCart.CreateWithItems(1, new List <CartItem> {
                CartItem.Create(1, 1, 9.99m, 1)
            });

            Assert.AreEqual(1, cart.CartItems.Count());
            Assert.AreEqual(9.99m, cart.CartItems.Single().CurrentPrice);
        }
コード例 #4
0
        public void AddItemToCart(Cart cart, string sku, int quantity)
        {
            var catalogItem = _context.CatalogItem
                              .FirstOrDefault(x => x.Sku == sku);

            var cartItem = CartItem.Create(catalogItem);

            cartItem.IncreaseQuantity(quantity);
            cart.CartItems.Add(cartItem);
        }
コード例 #5
0
        public void Create(List <CartItem> items, int cardId)
        {
            Delete(cardId);

            Cart cart = CartMobileService.Obj.GetById(cardId);

            foreach (var item in items)
            {
                CartItem cartItem = CartItem.Create(cart, item.Item, item.Status);

                var createdItem = repository.Create(cartItem);
            }
        }
コード例 #6
0
        //     private SalesContext CreateAndSeedContext()
        //   {
        //        var optionsBuilder = new DbContextOptionsBuilder<SalesContext>();
        //         optionsBuilder.UseInMemoryDatabase();
        //    var context = new SalesContext(_config,optionsBuilder.Options);
        //      context.Database.EnsureDeleted();
        //    context.Database.EnsureCreated();
        //     context.CartItem.AddRange(BuildCartItems());
        //     context.SaveChanges();
        //      return context;

        //    }
        private List <CartItem> BuildCartItems()
        {
            var cartItems = new List <CartItem>
            {
                CartItem.Create("adwa33dda", 1, 2),
                CartItem.Create("cyscysa33dda", 4, 21),
                CartItem.Create("adwa33dda", 5, 10),
                CartItem.Create("r23fwsda", 4, 200),
                CartItem.Create("adwa33dda", 2, 4),
                CartItem.Create("adwa33dda", 3, 7),
                CartItem.Create("543gsvsdda", 2, 88)
            };

            return(cartItems);
        }
コード例 #7
0
        public async Task <IActionResult> AddRecipeToCart(Guid recipeId)
        {
            if (recipeId == null)
            {
                return(BadRequest());
            }

            var recipe = await recipesService.FindAsync(recipeId);

            if (recipe == null)
            {
                return(NotFound());
            }

            var userId   = Guid.Parse(User.FindFirstValue(KnownClaims.UserId));
            var cartItem = CartItem.Create(userId, recipe);
            await cartService.AddAsync(cartItem);

            return(new StatusCodeResult((int)HttpStatusCode.Created));
        }
コード例 #8
0
ファイル: CartHelper.cs プロジェクト: tfalise/TalentAgileShop
        public static void AddProduct(this List <CartItem> products, decimal price, int count = 1, ProductSize size = ProductSize.Small, string category = "No category", string country = "Nowhere")
        {
            var p = new Product()
            {
                Category = new Category()
                {
                    Name = category
                },
                Description = null,
                Id          = Guid.NewGuid().ToString(),
                Price       = price,
                Image       = null,
                Name        = "No name",
                Origin      = new Country()
                {
                    Name = country
                },
                Size = size
            };

            products.Add(CartItem.Create(p, count));
        }
コード例 #9
0
        public async Task <IHttpActionResult> CreateCard(CreateCartBindingModel model)
        {
            User user = GetCurrentUser();

            Cart cart = null;

            if (!model.CartId.HasValue)
            {
                cart = Cart.Create(model.Title, model.Notes, model.Date);

                List <CartItem> items = model.Items?.Select(x => CartItem.Create(cart, Item.Create(x.Title, user), x.Status.Value)).ToList();

                cart = CartMobileService.Obj.Create(cart, user, items);

                // Make Sharing

                if (model.Users?.Count != 0 && model.Users != null)
                {
                    string userCode = UserCodeOperation.ProduceCode(cart.CartId, (int)AccessLevel.ReadWrite);

                    List <string> emails = model.Users.Select(x => x.Email).ToList();

                    User userToFind = null;

                    foreach (var email in emails)
                    {
                        if (email != user.Email)
                        {
                            userToFind = UserService.Obj.FindByEmail(email);

                            if (userToFind != null)
                            {
                                Cart cartToFind = CartMobileService.Obj.GetById(cart.CartId);

                                CartOwner cartOwner = CartOwner.Create(cartToFind, userToFind, AccessLevel.ReadWrite);

                                CartOwnerMobileService.Obj.Create(cartOwner);

                                await UserService.Obj.SendEmailToShareCard(userToFind.Email, userCode);
                            }

                            else
                            {
                                await UserService.Obj.SendEmailToShareCard(email, userCode);
                            }
                        }
                    }
                }
            }

            else
            {
                cart = CartMobileService.Obj.GetById(model.CartId.Value);
                cart.Update(model.Title, model.Notes, model.Date);

                List <CartOwner> users = new List <CartOwner>();

                if (model.Users != null)
                {
                    users = model.Users.Select(x => CartOwner.Create(cart, UserService.Obj.FindById(x.UserId), x.AccessLevel)).ToList();
                }

                List <CartItem> items = model.Items?.Select(x => CartItem.Create(cart, Item.Create(x.Title, user), x.Status.Value)).ToList();

                users.Add(CartOwner.Create(cart, user, AccessLevel.Owner));

                CartMobileService.Obj.Update(cart, items, users);
            }

            CartIndexBindingModel bindingModel = getCartIndexBindingModel(cart);

            return(Ok(bindingModel));
        }