/// <summary>
        /// Deletes a product.
        /// </summary>
        /// <param name="productDel">Product to delete</param>
        public void Delete(ProductDTO productDel)
        {
            // Throws an exception for a null dto
            if (productDel == null)
                throw new ArgumentNullException("productDel",
                    "productDel does not accept a null dto as an argument.");

            using (var context = new openTillEntities())
            {
                var product = context.Products.SingleOrDefault(p => p.UPC == productDel.UPC);

                // Throws an exception if no matching entry is found
                if (product == null)
                    throw new InvalidOperationException("No entry matching the given product was found.");

                context.Products.Remove(product);
                context.SaveChanges();
            }
        }
 /// <summary>
 /// Default constructor, sets the ProductDTO represented by this TransactionItem
 /// </summary>
 /// <param name="item">the ProductDTO this object will represent</param>
 public TransactionItem(ProductDTO item)
 {
     Item = new ObservableProduct(item);
 }
 public ObservableProduct(ProductDTO dto)
 {
     UPC = dto.UPC;
     CategoryListID = dto.CategoryListID;
     BrandID = dto.BrandID;
     Name = dto.Name;
     Description = dto.Description;
     StoreCost = dto.StoreCost;
     SellingPrice = dto.SellingPrice;
     MinOnHand = dto.MinOnHand;
     OnHand = dto.OnHand;
     HasDeposit = dto.HasDeposit;
     IsTaxable = dto.IsTaxable;
     MinimumAge = dto.MinimumAge;
     CategoryList = dto.CategoryList;
     ProductState = State.Unmodified;
 }
        /// <summary>
        /// Updates an existing product.
        /// </summary>
        /// <param name="productUpdate">Product to update</param>
        public void Update(ProductDTO productUpdate)
        {
            // Throws an exception for a null dto
            if (productUpdate == null)
                throw new ArgumentNullException("productUpdate",
                    "productUpdate does not accept a null dto as an argument.");

            using (var context = new openTillEntities())
            {
                var product = context.Products.SingleOrDefault(p => p.UPC == productUpdate.UPC);

                // Throws an exception if no matching product is fonud
                if (product == null)
                    throw new InvalidOperationException("No product with the given upc exists.");

                // Update existing product
                product.BrandId = productUpdate.BrandID;
                product.Description = productUpdate.Description;
                product.Name = productUpdate.Name;
                product.OnHand = productUpdate.OnHand;
                product.MinOnHand = productUpdate.MinOnHand;
                product.HasDeposit = productUpdate.HasDeposit;
                product.IsTaxable = productUpdate.IsTaxable;
                product.StoreCost = productUpdate.StoreCost;
                product.SellingPrice = productUpdate.SellingPrice;
                product.MinimumAge = (byte?)productUpdate.MinimumAge;

                context.SaveChanges();
            }
        }
        /// <summary>
        /// Submits a new product for persistence.
        /// </summary>
        /// <param name="newProduct">New product to save</param>
        public void Insert(ProductDTO newProduct)
        {
            // Throws an exception for a null dto
            if (newProduct == null)
                throw new ArgumentNullException("newProduct",
                    "newProduct does not accept a null dto as an argument.");

            using (var context = new openTillEntities())
            {
                // Throws exception if a product with the given upc already exists
                if (context.Products.SingleOrDefault(p => p.UPC == newProduct.UPC) != null)
                    throw new InvalidOperationException("A product with the given upc already exists.");

                context.Products.Add(Mapper.Map<Product>(newProduct));
                context.SaveChanges();
            }
        }
 /// <summary>
 /// Method calls on repository to save a Product.
 /// </summary>
 /// <param name="product">The Product to be saved.</param>
 public void SaveProduct(ProductDTO product)
 {
     _productRepository.Insert(product);
 }
 /// <summary>
 /// Method calls on repository to delete a Product.
 /// </summary>
 /// <param name="product">The Product to be deleted.</param>
 public void RemoveProduct(ProductDTO product)
 {
     _productRepository.Delete(product);
 }