Пример #1
0
        public void Update_Product()
        {
            //Arrange
            var product = buildModels.GetProduct(1);

            //Act
            product.ProductName = product.ProductName + "...";
            //Assert
            buildModels.UpdateProduct().Should().Be(1);
        }
Пример #2
0
        public HttpResponseMessage PutProduct(ProductViewModel productModel)
        {
            if (!ModelState.IsValid)
            {
                return(ReturnResponse(new Object(), null, string.Empty, HttpStatusCode.BadRequest, "Not a valid model"));
            }

            var prodContext = new DataLayer.Product();

            if (productModel.ProductID > 0)
            {
                prodContext = _buildModelsService.GetProduct(productModel.ProductID);

                if (prodContext != null)
                {
                    prodContext.ProductName     = productModel.ProductName;
                    prodContext.CategoryID      = productModel.CategoryID;
                    prodContext.Discontinued    = productModel.Discontinued;
                    prodContext.QuantityPerUnit = productModel.QuantityPerUnit;
                    prodContext.ReorderLevel    = productModel.ReorderLevel;
                    prodContext.SupplierID      = productModel.SupplierID;
                    prodContext.UnitPrice       = productModel.UnitPrice;
                    prodContext.UnitsInStock    = productModel.UnitsInStock;
                    prodContext.UnitsOnOrder    = productModel.UnitsOnOrder;

                    _buildModelsService.UpdateProduct();
                    productModel = Mapper.Map <ProductViewModel>(prodContext);
                    return(ReturnResponse(productModel, new JsonMediaTypeFormatter(), "application/json", HttpStatusCode.OK, string.Empty));
                }
                else
                {
                    return(ReturnResponse(new Object(), null, string.Empty, HttpStatusCode.NotFound, "Unable to find the product"));
                }
            }

            return(PostProduct(productModel));
        }