Пример #1
0
        /// <summary>
        /// Filters The query by ProductCode
        /// </summary>
        public static IQueryable<ProductReview> ReviewsForProduct(this IQueryable<ProductReview> qry,
            Product p) {

            return from r in qry
                   where r.ProductID == p.ID
                   select r;
        }
        public void SetProductInventoryStatus(Product product, InventoryStatus status) {

            product.Inventory = status;
            _catalogService.SaveProduct(product);
            
            
        }
Пример #3
0
        /// <summary>
        /// Filters The query by Product
        /// </summary>
        public static IQueryable<ProductImage> ImagesForProduct(this IQueryable<ProductImage> qry,
            Product p) {

            return from i in qry
                   where i.ProductID == p.ID
                   select i;
        }
        public void SetProductInventoryStatus(Product product) {

            //pull the amount on hand
            int amountOnHand = GetAmountOnHand(product.ID);
            InventoryStatus status;

            //this is where the inventorying logic lives; how you set it depends on 
            //your business requirements.

            if (amountOnHand > 0) {
                status = InventoryStatus.InStock;
                product.EstimatedDelivery = "2-3 Days";
            } else {

                if (product.AllowBackOrder) {
                    status = InventoryStatus.BackOrder;
                    product.EstimatedDelivery = "2-3 Weeks";
                } else {
                    status = InventoryStatus.CurrentlyUnavailable;
                    product.EstimatedDelivery = " -- ";
                }
            }

            //save the status
            SetProductInventoryStatus(product, status);

        }
Пример #5
0
 public OrderItem(Guid orderID, Product product, int quantity)
     {
     this.OrderID = orderID;
     this.Product = product;
     this.Quantity = quantity;
     if (this.Product != null)
     {
         this.LineItemPrice = product.DiscountedPrice;
     }
 }
Пример #6
0
        public void Product_ShouldHave_Name_Description__Price_Discount_WeightInPounds_Fields() {

            Product p = new Product("TestName", "TestDescription",
                100, 20,5);

            Assert.AreEqual("TestName", p.Name);
            Assert.AreEqual("TestDescription", p.Description);
            Assert.AreEqual(20, p.DiscountPercent);
            Assert.AreEqual(100, p.Price);
            Assert.AreEqual(5, p.WeightInPounds);

        }
Пример #7
0
        /// <summary>
        /// Adds a product to the cart
        /// </summary>
        public void AddItem(Product product, int quantity) {

            //see if this item is in the cart already
            OrderItem item = FindItem(product);

            if (quantity != 0) {
                if (item != null) {
                    //if the passed in amount is 0, do nothing
                    //as we're assuming "add 0 of this item" means
                    //do nothing
                    if (quantity != 0)
                        AdjustQuantity(product, item.Quantity + quantity);
                } else {
                    if (quantity > 0) {
                        item = new OrderItem(this.ID,product, quantity);
                        
                        //add to list
                        this.Items.Add(item);
                    }
                }

            }

        }
Пример #8
0
 /// <summary>
 /// Adds a product to the cart
 /// </summary>
 public void AddItem(Product product) {
     AddItem(product, 1);
 }
Пример #9
0
        /// <summary>
        /// Finds an item in the cart
        /// </summary>
        /// <param name="product"></param>
        /// <returns></returns>
        public OrderItem FindItem(Product product) {
            OrderItem result = null;
            if (product != null) {
                //see if this item is in the cart already
                return FindItem(product.ID);
            }
            return result;

        }
Пример #10
0
 /// <summary>
 /// Remmoves a product from the cart
 /// </summary>
 public void RemoveItem(Product product) {
     RemoveItem(product.ID);
 }
Пример #11
0
        /// <summary>
        /// Adjusts the quantity of an item in the cart
        /// </summary>
        public void AdjustQuantity(Product product, int newQuantity) {
            OrderItem itemToAdjust = FindItem(product);
            if (itemToAdjust != null) {
                if (newQuantity <= 0) {
                    this.RemoveItem(product);
                } else {
                    itemToAdjust.Quantity = newQuantity;
                }

            }

        }
Пример #12
0
 public void Product_Should_Have_InventoryStatus_InStock_ByDefault() {
     Product p = new Product("test", "test", 1M, 0, 1M);
     Assert.AreEqual(InventoryStatus.InStock, p.Inventory);
 }
        private static void PopulateSqlDatabase(List<MongoProduct> list)
        {
            using (var uow = CommerceModelUnitOfWork.UnitOfWork()) {
                var categories = uow.Categories.ToDictionary(item => item.CategoryName, StringComparer.OrdinalIgnoreCase);
                var publishers = uow.Publishers.ToDictionary(item => item.PublisherName, StringComparer.OrdinalIgnoreCase);

                foreach (var categoryName in list.Where(item => !string.IsNullOrWhiteSpace(item.Binding)).Select(item => item.Binding).ToList().Distinct()) {
                    Category category = null;
                    if (!categories.TryGetValue(categoryName, out category)) {
                        category = new Category() {
                            CategoryName = categoryName
                        };
                        categories.Add(categoryName, category);
                        uow.Add(category);
                    }
                }

                foreach (var publisherName in list.Where(item => !string.IsNullOrWhiteSpace(item.Publisher)).Select(item => item.Publisher).ToList().Distinct()) {
                    Publisher publisher = null;
                    if (!publishers.TryGetValue(publisherName, out publisher)) {
                        publisher = new Publisher() {
                            PublisherName = publisherName
                        };
                        publishers.Add(publisherName, publisher);
                        uow.Add(publisher);
                    }
                }

                foreach (var sourceProduct in list) {
                    Category category = null;
                    Publisher publisher = null;
                    if (!string.IsNullOrWhiteSpace(sourceProduct.Binding)) {
                        category = categories[sourceProduct.Binding];
                    }
                    if (!string.IsNullOrWhiteSpace(sourceProduct.Publisher)) {
                        publisher = publishers[sourceProduct.Publisher];
                    }
                    if (sourceProduct.PackageDimensions == null) {
                        sourceProduct.PackageDimensions = new Dimension();
                    }
                    var product = new Product() {
                        Asin = sourceProduct.ASIN,
                        BuyItNowPrice = sourceProduct.BuyItNowPrice,
                        Category = category,
                        EsrbAgeRating = sourceProduct.ESRBAgeRating,
                        Feature = string.Join(Environment.NewLine, sourceProduct.Feature),
                        Format = sourceProduct.Format,
                        Genre = sourceProduct.Genre.MaxLength(75),
                        HardwarePlatform = sourceProduct.HardwarePlatform.MaxLength(75),
                        Height = sourceProduct.PackageDimensions.Height,
                        LargeImage = sourceProduct.LargeImage,
                        Length = sourceProduct.PackageDimensions.Length,
                        ListPrice = sourceProduct.ListPrice,
                        Manufacturer = sourceProduct.Manufacturer,
                        Model = sourceProduct.Model,
                        PartNumber = sourceProduct.PartNumber,
                        ProductGroup = sourceProduct.ProductGroup,
                        Publisher = publisher,
                        Title = sourceProduct.Title.MaxLength(250),
                        Weight = sourceProduct.PackageDimensions.Weight,
                        Width = sourceProduct.PackageDimensions.Width
                    };
                    uow.Add(product);
                }

                var sw = new Stopwatch();
                sw.Start();

                uow.SaveChanges();

                sw.Stop();

                Console.WriteLine(sw.ElapsedMilliseconds);
                Console.ReadLine();
            }
        }
Пример #14
0
 public OrderItem(Guid orderID, Product product)
     : this(orderID, product, 1) {
 }
Пример #15
0
        public void Catalog_Repository_Should_Insert_New_Product_On_Save() {
            Product p = new Product("TestName", "TestDescription",
                100, 20, 5);

            int productCount = _catalogRepository.GetProducts().Count();

            _catalogRepository.SaveProduct(p);

            int productCount2 = _catalogRepository.GetProducts().Count();

            Assert.IsTrue(productCount2 == productCount + 1);

        }
        public TestCatalogRepository() {
            
            //load up the repo list
            productList = new List<Product>();
            categoryList = new List<Category>();

            for (int i = 1; i <= 5; i++) {
                Product p = new Product();
                p.Name = "Product" + i.ToString();
                p.ID = i;
                p.Price = 10M;
                p.Description = "Test Description";
                p.ProductCode = "SKU" + i.ToString();
                p.WeightInPounds = 5;


                //set first three products to shipped
                p.Delivery = i <= 3 ? DeliveryMethod.Shipped : DeliveryMethod.Download;


                //set first three products to Back-orderable
                p.AllowBackOrder = i <= 3;

                //set the 2nd product to BackOrder
                p.Inventory = i == 2 ? InventoryStatus.BackOrder : InventoryStatus.InStock;

                //set all products to taxable, except the 5th
                p.IsTaxable = i != 5;


                //add three images
                p.Images = new LazyList<ProductImage>(GetProductImages().Take(3));
                //reviews
                p.Reviews = new LazyList<ProductReview>(GetReviews().Take(5));
                p.Descriptors = new LazyList<ProductDescriptor>();

                //descriptors
                p.Descriptors.Add(new ProductDescriptor(p.ID, "Test", "Body"));
                p.Recommended = new LazyList<Product>();

                //have it recommend itself, for now
                p.Recommended.Add(p);

                //related
                p.RelatedProducts = new LazyList<Product>();
                p.RelatedProducts.Add(new Product("rel1", "test", 1, 0, 5));
                p.RelatedProducts.Add(new Product("rel1", "test", 1, 0, 5));
                p.RelatedProducts.Add(new Product("rel1", "test", 1, 0, 5));
                p.RelatedProducts.Add(new Product("rel1", "test", 1, 0, 5));

                //add some Crosses
                p.CrossSells = new LazyList<Product>();
                p.CrossSells.Add(new Product("cross1", "test", 1, 0, 5));
                p.CrossSells.Add(new Product("cross2", "test", 1, 0, 5));
                p.CrossSells.Add(new Product("cross3", "test", 1, 0, 5));
                productList.Add(p);
            }

            //categories
            for (int i = 1; i <= 10; i++)
            {

                Category c = new Category();
                c.ID = i;
                c.IsDefault = i == 1;
                c.Name = "Parent" + i.ToString();
                c.ParentID = 0;
                c.Image = new CategoryImage("thumb", "full");

                int subCategoryID = 10 * i;
                for (int x = 10; x <= 20; x++)
                {
                    Category sub = new Category();
                    sub.ID = subCategoryID;
                    sub.Name = "Sub" + x.ToString();
                    sub.ParentID = i;
                    sub.Image = new CategoryImage("thumb", "full");

                    //add some products
                    sub.Products = new LazyList<Product>();
                    for (int p = 1; p <= 5; p++)
                    {
                        sub.Products.Add(productList[p-1]);
                    }


                    categoryList.Add(sub);
                    subCategoryID++;
                }
                categoryList.Add(c);
            }


        }
        public void SaveProduct(Product product) {
            
            //find the Product
            Product p = productList.Where(x => x.ID == product.ID).SingleOrDefault();
            if (p != null) {
                p = product;
            } else {
                productList.Add(product);
            }


        }
Пример #18
0
 public OrderItem(Product product, int quantity)
     : this(Guid.Empty, product, quantity) {
 }
Пример #19
0
 /// <summary>
 /// Saves the core product information to the DB
 /// </summary>
 /// <param name="p"></param>
 public void SaveProduct(Product p) {
     _repository.SaveProduct(p);
 }
 public void SaveProductView(string userName, string IP, Product product) {
     //track this request
     UserEvent ue = new UserEvent(userName, IP,
         null,product.ID, System.Guid.Empty, UserBehavior.ViewProduct);
     _pRepo.Save(ue);
 }