public void TestAddOrUpdate()
        {
            //add
            DateTime dtRegistration = DateTime.Now.Date.AddDays(-2).AddHours(12.50);
            User     user           = new User("Jake", 27, dtRegistration);

            userRepo.AddOrUpdate(user);
            unitOfwork.Save();
            User userInDb = userRepo.FindByName("Jake");

            Assert.AreEqual(user.Name, userInDb.Name);

            //update
            userInDb.Age = 29;
            userRepo.AddOrUpdate(userInDb);


            //add categories to db
            foreach (var item in categories)
            {
                categoryRepo.AddOrUpdate(item);
            }
            unitOfwork.Save();

            //assign the category to products and add to db
            foreach (var item in products)
            {
                if (item.Name.Contains("Sumsung"))
                {
                    item.Category = categories[1];
                }
                else
                {
                    item.Category = categories[0];
                }

                productRepo.AddOrUpdate(item);
            }
            unitOfwork.Save();

            //add products to stores
            Store rozetkaStore = stores[0];

            rozetkaStore.Products.Add(products[0]);
            rozetkaStore.Products.Add(products[2]);
            rozetkaStore.Products.Add(products[1]);

            Store mobidickStore = stores[1];

            mobidickStore.Products.Add(products[0]);
            mobidickStore.Products.Add(products[3]);
            mobidickStore.Products.Add(products[2]);

            //add stores to db
            storeRepo.AddOrUpdate(rozetkaStore);
            storeRepo.AddOrUpdate(mobidickStore);
            unitOfwork.Save();

            unitOfwork.Dispose();
        }
        public void AddToCart(BookModel book)
        {
            // Get the matching cart and album instances
            var cartItem = store.GetCarts().FirstOrDefault(s => s.CartId.Equals(ShoppingCartId) && s.BookId.Equals(book.BookId)); //storeDB.Carts.SingleOrDefault(c => c.CartId == ShoppingCartId && c.AlbumId == album.AlbumId);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists
                cartItem = new API.Models.Cart
                {
                    BookId      = book.BookId,
                    CartId      = ShoppingCartId,
                    Count       = 1,
                    DateCreated = DateTime.Now
                };

                store.AddOrUpdate(cartItem);

                //storeDB.Carts.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart, then add one to the quantity
                cartItem.Count++;
            }

            // Save changes
            store.SaveChanges();
        }
Exemple #3
0
        public void TestAddOrUpdateProduct()
        {
            //add categories to db
            foreach (var item in categories)
            {
                categoryRepo.AddOrUpdate(item);
            }
            categoryRepo.Save();

            //assign the category to products and add to db
            foreach (var item in products)
            {
                if (item.Name.Contains("Sumsung"))
                {
                    item.Category = categories[1];
                }
                else
                {
                    item.Category = categories[0];
                }

                productRepo.AddOrUpdate(item);
            }
            productRepo.Save();

            //add products to stores
            Store rozetkaStore = stores[0];

            rozetkaStore.Products.Add(products[0]);
            rozetkaStore.Products.Add(products[2]);
            rozetkaStore.Products.Add(products[1]);

            Store mobidickStore = stores[1];

            mobidickStore.Products.Add(products[0]);
            mobidickStore.Products.Add(products[3]);
            mobidickStore.Products.Add(products[2]);

            //add stores to db
            storeRepo.AddOrUpdate(rozetkaStore);
            storeRepo.AddOrUpdate(mobidickStore);
            storeRepo.Save();
        }
        public async Task <IActionResult> InitializeDatabase(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "init")] HttpRequest req,
            ILogger log)
        {
            await _cosmos.ResetDatabase();

            // Stores
            Store toolShack = await _stores.AddOrUpdate(new Store
            {
                Id          = Guid.Parse("10000000-0000-0000-0000-000000000001"),
                Name        = "Tool Shack",
                PhoneNumber = "(555) 555-5501"
            });

            Store toolRentalSuperstore = await _stores.AddOrUpdate(new Store
            {
                Id          = Guid.Parse("10000000-0000-0000-0000-000000000002"),
                Name        = "Tool Rental Superstore",
                PhoneNumber = "(555) 555-5502"
            });

            // Tools
            await _tools.AddOrUpdate(new Tool
            {
                Id          = Guid.Parse("20000000-0000-0000-0000-000000000001"),
                StoreId     = toolShack.Id,
                HourlyPrice = 50.0m,
                Name        = "Jackhammer"
            });

            await _tools.AddOrUpdate(new Tool
            {
                Id          = Guid.Parse("20000000-0000-0000-0000-000000000002"),
                StoreId     = toolShack.Id,
                HourlyPrice = 25.0m,
                Name        = "Rotary Hammer Drill"
            });

            await _tools.AddOrUpdate(new Tool
            {
                Id          = Guid.Parse("20000000-0000-0000-0000-000000000003"),
                StoreId     = toolRentalSuperstore.Id,
                HourlyPrice = 250.0m,
                Name        = "Skid Steer"
            });

            await _tools.AddOrUpdate(new Tool
            {
                Id          = Guid.Parse("20000000-0000-0000-0000-000000000004"),
                StoreId     = toolRentalSuperstore.Id,
                HourlyPrice = 39.0m,
                Name        = "Core Aerator"
            });

            await _tools.AddOrUpdate(new Tool
            {
                Id          = Guid.Parse("20000000-0000-0000-0000-000000000004"),
                StoreId     = toolRentalSuperstore.Id,
                HourlyPrice = 25.0m,
                Name        = "Extension Ladder"
            });

            return(new OkObjectResult("Database initialized."));
        }