Exemple #1
0
 public virtual void RemoveProduct(Product product)
 {
     Products.Remove(product);
 }
        /// <summary>
        /// Creates a new Business Product and adds it to a business
        /// </summary>
        /// <param name="businessId">businessId</param>
        /// <param name="businessVersion">businessVersion</param>
        /// <param name="product">product to be created</param>
        public void CreateNewBusinessProduct(int businessId, int businessVersion, Product product)
        {
            try
            {
                IBusinessInformationDAO businessInformationDAO = _daoFactory.GetBusinessInformationDAO ();

                //Get all the business products. Note that I retrieve all products in a batch base
                //and don't care about the number of records. This is because it is not likely
                //the business will contain hundreds of products
                BusinessInformation businessInformation = businessInformationDAO.FindByIdAndVersion (
                    businessId,
                    businessVersion);

                if (businessInformation == null)
                    throw new ZiblerBusinessComponentsException (Resources.RecordNotFound);
                else
                {
                    foreach (Product existingProduct in businessInformation.Products)
                    {
                        if (existingProduct.Name == product.Name)
                        {
                            //Throw an exception and indicate the product already exists
                            throw new ZiblerBusinessComponentsException (
                                Resources.LoanRequestOperationsMsgBusinessAlreadyHasProduct);
                        }
                    }

                    //Since no exception was thrown, then we add the new product to the list.
                    businessInformation.AddProduct (product);
                }
            }
            /* If the exception was thrown here, just pass it up */
            catch (ZiblerBusinessComponentsException ex)
            {
                throw;
            }
            /* Catch any Data Layer or other exception and throw an unkown exception */
            catch (Exception ex)
            {
                ZiblerBusinessComponentsUnknownException exc
                = new ZiblerBusinessComponentsUnknownException (ex);

                /* Throw the new exception */
                throw exc;
            }
        }
Exemple #3
0
 public virtual void AddProduct(Product newProduct)
 {
     newProduct.BusinessInformation = this;
     Products.Add(newProduct);
 }