Beispiel #1
0
        public ProductCopy AddProductCopy(Product product, string description, double price, int count)
        {
            ProductCopy productCopy = new ProductCopy(product, description, price, count);

            repository.AddProductCopy(productCopy);
            return(productCopy);
        }
Beispiel #2
0
 public void TestInitialize()
 {
     Employee.ResetIndex();
     Product.ResetIndex();
     ProductCopy.ResetIndex();
     dataSource = new XMLDataSource();
 }
Beispiel #3
0
        public Order AddOrder(Employee employee, ProductCopy productCopy, double price, int count)
        {
            Order order = new Order(employee, productCopy, price, count);

            repository.AddOrder(order);
            return(order);
        }
Beispiel #4
0
 public bool DeleteProductCopy(ProductCopy productCopy)
 {
     try {
         return(dataContext.productCopies.Remove(productCopy));
     }
     catch (Exception) {
         return(false);
     }
 }
Beispiel #5
0
 public bool DeleteProductCopy(Func <ProductCopy, bool> condition)
 {
     try {
         ProductCopy productCopy = FindProductCopy(condition);
         return(repository.DeleteProductCopy(productCopy));
     } catch (Exception) {
         return(false);
     }
 }
Beispiel #6
0
        public void UpdateProductCopy(ProductCopy productCopy)
        {
            ProductCopy updatingCopy = GetProductCopyById(productCopy.GetId());

            if (updatingCopy != null)
            {
                updatingCopy.SetProduct(productCopy.GetProduct());
                updatingCopy.SetDescription(productCopy.GetDescription());
                updatingCopy.SetPrice(productCopy.GetPrice());
                updatingCopy.SetCount(productCopy.GetCount());
            }
        }
Beispiel #7
0
        public void Product_AddAndRemoveProductCopy()
        {
            // Arrange
            ProductCopy productCopy  = dataSource.GetProductCopies()[0];
            int         copiesBefore = product.GetProductCopies().Count;

            // Act
            product.AddProductCopy(productCopy);
            // Assert
            Assert.AreEqual(copiesBefore, 1);
            Assert.AreEqual(product.GetProductCopies().Count, 2);
        }
Beispiel #8
0
 public void DataRepositoryProductCopies_GetProductCopyById()
 {
     try {
         //Arrange
         ProductCopy productCopyFromDataSource = dataRepository.GetAllProductCopies()[0];
         ProductCopy productCopy = dataRepository.GetProductCopyByIndex(0);
         //Assert
         Assert.AreEqual(productCopy, productCopyFromDataSource);
     }
     catch {
         Assert.Fail();
     }
 }
Beispiel #9
0
        public void ProductCopiesDeserialization()
        {
            // Arrange
            ObservableCollection <ProductCopy> productCopies = dataSource.GetProductCopies();
            ProductCopy productCopy = new ProductCopy(
                id: 0,
                product: dataSource.GetProducts()[2],
                description: "That's it! You people have stood in my way long enough. I'm going to clown college!",
                price: 12.02,
                count: 1
                );

            // Assert
            Assert.AreEqual(30, productCopies.Count);
            Assert.AreEqual(productCopy, productCopies[0]);
        }
Beispiel #10
0
        public void DataRepositoryProductCopies_UpdateProductCopy()
        {
            //Arrange
            ProductCopy productCopy = new ProductCopy(
                id: 0,
                product: dataRepository.GetProductByIndex(1),
                description: "Granit",
                price: 12.0,
                count: 1
                );

            //Act
            dataRepository.UpdateProductCopy(productCopy);
            //Assert
            Assert.AreEqual(dataRepository.GetProductCopyByIndex(0), productCopy);
        }
Beispiel #11
0
        public Guid Create(Guid deliveryAddressId, ApplicationUser user)
        {
            List <Product> products = new List <Product>();

            foreach (ItemInCartViewModel item in GetCart())
            {
                if (item.Quantity <= item.Product.ItemsAvailable)
                {
                    for (int i = 0; i < item.Quantity; i++)
                    {
                        products.Add(item.Product);
                    }
                }
                else
                {
                    throw new Exception("Not enough products in stock");
                }
            }
            Order newOrder = new Order();

            newOrder.OrderId           = Guid.NewGuid();
            newOrder.DateOfPurchase    = DateTime.Now;
            newOrder.OrderState        = OrderState.New;
            newOrder.DeliveryAddressId = deliveryAddressId;
            newOrder.UserId            = user.Id;
            _dbContext.Orders.Add(newOrder);
            foreach (Product product in products)
            {
                Product tempProd = _dbContext.Products.FirstOrDefault(p => p.ProductId == product.ProductId);
                if (tempProd.ItemsAvailable > 0)
                {
                    ProductCopy newCopy = new ProductCopy();
                    newCopy.ProductCopyId = Guid.NewGuid();
                    newCopy.ProductId     = product.ProductId;
                    newCopy.Price         = product.Price;
                    newCopy.OrderId       = newOrder.OrderId;
                    _dbContext.ProductsCopies.Add(newCopy);
                    tempProd.ItemsAvailable--;
                    _dbContext.Entry(tempProd).Property(p => p.ItemsAvailable).IsModified = true;
                    _dbContext.SaveChanges();
                }
            }
            _dbContext.SaveChanges();
            EmptyCart();
            return(newOrder.OrderId);
        }
Beispiel #12
0
 public void DataRepositoryProductCopies_AddAndDeleteProductCopies()
 {
     try {
         //Arrange
         ProductCopy productCopy = new ProductCopy(dataRepository.GetProductByIndex(1), "Heavy Duty Linen Plate", 7.8, 1);
         //Act
         dataRepository.AddProductCopy(productCopy);
         ProductCopy firstCheck = dataRepository.GetProductCopyById(1);
         dataRepository.DeleteProductCopy(productCopy);
         ProductCopy secondCheck = dataRepository.GetProductCopyById(1);
         //Assert
         Assert.AreEqual(firstCheck, productCopy);
         Assert.IsNull(secondCheck);
     }
     catch {
         //Assert
         Assert.Fail();
     }
 }
Beispiel #13
0
        public void DataRepositoryOrders_AddAndDeleteOrders()
        {
            //Arrange
            Employee    employee    = new Employee(id: 0, firstName: "Anakin", lastName: "Calrissian");
            Product     product     = new Product("Product name", 10.0);
            ProductCopy productCopy = new ProductCopy(product, "description", 12, 1);
            Order       order       = new Order(employee, productCopy, 12.0, 1);

            //Act
            dataRepository.AddOrder(order);
            Order firstCheck = dataRepository.GetOrderByIndex(1);

            dataRepository.DeleteOrder(order);
            Order secondCheck = dataRepository.GetOrderByIndex(1);

            //Assert
            Assert.AreEqual(firstCheck, order);
            Assert.IsNull(secondCheck);
        }
Beispiel #14
0
        public void Buy(Product productToBuy, ApplicationUser user)
        {
            Order order = new Order()
            {
                OrderId        = Guid.NewGuid(),
                OrderState     = OrderState.New,
                DateOfPurchase = DateTime.Now,
                UserId         = user.Id
            };

            _dbContext.Orders.Add(order);
            _dbContext.SaveChanges();
            ProductCopy boughtItem = new ProductCopy()
            {
                ProductCopyId = Guid.NewGuid(),
                ProductId     = productToBuy.ProductId,
                Price         = productToBuy.Price,
                OrderId       = order.OrderId
            };

            productToBuy.ItemsAvailable--;
            _dbContext.ProductsCopies.Add(boughtItem);


            // todo shopping cart

            Order newOrder          = new Order();
            List <ProductCopy> list = new List <ProductCopy>();

            list.Add(boughtItem);
            newOrder.OrderId         = Guid.NewGuid();
            newOrder.DateOfPurchase  = DateTime.Now;
            newOrder.ProductsInOrder = list;
            newOrder.UserId          = user.Id;
            _dbContext.Orders.Add(newOrder);
            _dbContext.SaveChanges();
        }
Beispiel #15
0
 public void TestInitialize()
 {
     ProductCopy.ResetIndex();
     dataRepository = new DataRepository(new TestDataSource());
     productCopy    = dataRepository.GetAllProductCopies()[0];
 }
Beispiel #16
0
 // CRUD methods for ProductCopies in this partial class
 public void AddProductCopy(ProductCopy productCopy)
 {
     dataContext.productCopies.Add(productCopy);
 }
Beispiel #17
0
 public void TestInitialize()
 {
     ProductCopy.ResetIndex();
     dataRepository = new DataRepository(new TestDataSource());
 }
Beispiel #18
0
 public void UpdateProductCopy(ProductCopy productCopy)
 {
     repository.UpdateProductCopy(productCopy);
 }