Пример #1
0
        public HttpResponseMessage ReduceSoldProduct(UpdateProductWM webModel)
        {
            try
            {
                var product = _productsManager.GetProduct(webModel.ProductID);

                if (product == null)
                {
                    throw new Exception(ErrorMessageConstants.ProductNotFound);
                }

                product.UnitsInStock = product.UnitsInStock - webModel.Quantity;

                if (product.UnitsInStock <= 0)
                {
                    throw new Exception(ErrorMessageConstants.MinusUnitsOnOrder);
                }

                product.UnitsOnOrder = product.UnitsOnOrder + webModel.Quantity;

                _productsManager.UpdateProduct(product);

                return(Request.CreateResponse(HttpStatusCode.Created));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.ToString()));
            }
        }
        public void TestGetProduct()
        {
            List <Product> products = CreateUniqueProductIdQualifiedProducts();

            _target.SetFieldOrProperty(MEMBER_VARIABLE_NAME_PRODUCTS, products);
            Assert.AreSame(_productsManager.GetProduct(-1), products[0]);
            Assert.ThrowsException <ArgumentException>(() => _productsManager.GetProduct(2));
        }
        public void CreateProduct()
        {
            ProductsManager productsManager = ProductsManager.GetManager();

            var productItem = productsManager.CreateProduct(ProductsIntegrationTests.productItemId);

            productItem.Title   = "Test Product";
            productItem.Content = "<h1>Simple content goes here ...</h1>";

            var taxManager = TaxonomyManager.GetManager();

            AddTaxaToProduct(productItem, taxManager, "Colors", ProductsIntegrationTests.colorName);

            productItem.WhatIsInTheBox  = "Summary goes here...";
            productItem.QuantityInStock = 1;
            productItem.Price           = 10;

            AddImageToProductItem(productItem);

            productsManager.SaveChanges();
            var contextBag = new Dictionary <string, string>();

            contextBag.Add("ContentType", productItem.GetType().FullName);

            string workflowOperation = "Publish";

            WorkflowManager.MessageWorkflow(
                productItem.Id,
                productItem.GetType(),
                "OpenAccessDataProvider",
                workflowOperation,
                false,
                contextBag);

            var product = productsManager.GetProduct(ProductsIntegrationTests.productItemId);

            Assert.IsNotNull(product);
            Assert.IsNotNull(product.GetValue("Colors"));
        }
 /// <summary>
 /// Get product by productId.
 /// </summary>
 public Product GetProduct(int productId)
 {
     return(_productsManager.GetProduct(productId));
 }
Пример #5
0
 public Product Get(Guid id)
 {
     return(_productsManager.GetProduct(id));
 }
 /// <summary>
 /// Initializes the order.
 /// </summary>
 private void InitializeOrder()
 {
     _order.AddProductToOrderIfProductIsNotInOrder(_productsManager.GetProduct(-1));
     _order.AddProductToOrderIfProductIsNotInOrder(_productsManager.GetProduct(0));
     _order.AddProductToOrderIfProductIsNotInOrder(_productsManager.GetProduct(3));
 }