public bool UpdateProduct(Product oldProduct, Product newProduct)
        {
            bool result = false;

            try
            {
                result = (1 == _productAccessor.UpdateProduct(oldProduct, newProduct));
                if (result == false)
                {
                    throw new ApplicationException("Product data not changed.");
                }

                if (oldProduct.Active != newProduct.Active)
                {
                    if (newProduct.Active == true)
                    {
                        _productAccessor.ReactivateProduct(oldProduct.ProductID);
                    }
                    else
                    {
                        _productAccessor.DeactivateProduct(oldProduct.ProductID);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Update Failed.", ex);
            }

            return(result);
        }
Beispiel #2
0
        public void TestDeactivateProduct()
        {
            //Arrange
            int    expected      = 1;
            string testProductID = "1234567890121";

            //Act
            int actual = _productAccessor.DeactivateProduct(testProductID);

            //Assert
            Assert.AreEqual(expected, actual);
        }
        /// Creator: Cash Carlson
        /// Created: 2020/04/29
        /// Approver: Rasha Mohammed
        ///
        /// Method to Deactivate Product by ProductID
        /// </summary>
        /// <param name="productID"></param>
        /// <returns></returns>
        public bool DeactivateProduct(string productID)
        {
            bool result = false;

            try
            {
                result = _productAccessor.DeactivateProduct(productID) == 1;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Deactivation failed", ex);
            }

            return(result);
        }