Пример #1
0
 private ProductEntity TranslateProductContractDataToProductEntity(
     Product product)
 {
     return new ProductEntity
                {
                    ProductID = product.ProductID,
                    ProductName = product.ProductName,
                    QuantityPerUnit = product.QuantityPerUnit,
                    UnitPrice = product.UnitPrice,
                    Discontinued = product.Discontinued
                };
 }
Пример #2
0
        public Product GetProduct(int id)
        {
            /*
            // TODO: call business logic layer to retrieve product
            Product product = new Product();
            product.ProductID = id;
            product.ProductName = 
                "fake product name from service layer";
            product.UnitPrice = 10.0m;
            product.QuantityPerUnit = "fake QPU";
            return product;
            */

            ProductBDO productBDO = null;
            try
            {
                productBDO = productLogic.GetProduct(id);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                string reason = "GetProduct Exception";
                throw new FaultException<ProductFault>
                    (new ProductFault(msg), reason);
            }

            if (productBDO == null)
            {
                string msg =
                    string.Format("No product found for id {0}",
                    id);
                string reason = "GetProduct Empty Product";
                if (id == 999)
                {
                    throw new Exception(msg);
                }
                else
                {
                    throw new FaultException<ProductFault>
                        (new ProductFault(msg), reason);
                }
            }
            Product product = new Product();
            TranslateProductBDOToProductDTO(productBDO, product);
            return product;
        }
Пример #3
0
        public bool UpdateProduct(Product product,
            ref string message)
        {
            bool result = true;

            // first check to see if it is a valid price
            if (product.UnitPrice <= 0)
            {
                message = "Price cannot be <= 0";
                result = false;
            }
            // ProductName can't be empty
            else if (string.IsNullOrEmpty(product.ProductName))
            {
                message = "Product name cannot be empty";
                result = false;
            }
            // QuantityPerUnit can't be empty
            else if (string.IsNullOrEmpty(product.QuantityPerUnit))
            {
                message = "Quantity cannot be empty";
                result = false;
            }
            else
            {
                ProductBDO productBDO = new ProductBDO();
                TranslateProductDTOToProductBDO(product, productBDO);

                try
                {
                    result = productLogic.UpdateProduct(
                        productBDO, ref message);
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                    string reason = "UpdateProduct Exception";
                    throw new FaultException<ProductFault>
                        (new ProductFault(msg), reason);
                }
            }
            return result;
        }
Пример #4
0
 private void TranslateProductDTOToProductBDO(
     Product product,
     ProductBDO productBDO)
 {
     productBDO.ProductID = product.ProductID;
     productBDO.ProductName = product.ProductName;
     productBDO.QuantityPerUnit = product.QuantityPerUnit;
     productBDO.UnitPrice = product.UnitPrice;
     productBDO.Discontinued = product.Discontinued;
 }
Пример #5
0
 public bool UpdateProduct(Product product)
 {
     var productEntity = TranslateProductContractDataToProductEntity(product);
     return _productLogic.UpdateProduct(productEntity);
 }