Example #1
0
        /// <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();
            }
        }
Example #2
0
        /// <summary>
        /// Updates an existing brand.
        /// </summary>
        /// <param name="brandUpdate">Brand to update</param>
        public void Update(BrandDTO brandUpdate)
        {
            // Throws an an exception for a null dto
            if (brandUpdate == null)
            {
                throw new ArgumentNullException("brandUpdate",
                                                "brandUpdate does not accept a null dot as an argument.");
            }

            using (var context = new openTillEntities())
            {
                var brand = context.Brands.SingleOrDefault(b => b.Id == brandUpdate.Id);

                // Throws an exception if the given brand doesn't exist
                if (brand == null)
                {
                    throw new InvalidOperationException("No entry matching the given brand was found.");
                }

                // Throws an exception if a brand with the given name already exists
                if (context.Brands.SingleOrDefault(b => b.Name == brandUpdate.Name) != null)
                {
                    throw new InvalidOperationException("A brand with the given brand name already exists.");
                }

                // Update existing brand
                brand.Name = brandUpdate.Name;

                context.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// Updates an existing category.
        /// </summary>
        /// <param name="categoryUpdate">Category to update</param>
        public void Update(CategoryDTO categoryUpdate)
        {
            // Throws an exception for a null dto
            if (categoryUpdate == null)
            {
                throw new ArgumentNullException("categoryUpdate",
                                                "categoryUpdate does not accept a null dto as an argument.");
            }

            using (var context = new openTillEntities())
            {
                var category = context.Categories.SingleOrDefault(c => c.Id == categoryUpdate.Id);

                // Throws an exception if the given category doesn't exist
                if (category == null)
                {
                    throw new InvalidOperationException("No entry matching the given category was found.");
                }

                // Throws an exception if a category with the given name already exists
                if (context.Categories.SingleOrDefault(c => c.Name == categoryUpdate.Name) != null)
                {
                    throw new InvalidOperationException("A category with the given name already.");
                }

                // Update existing category
                category.Name        = categoryUpdate.Name;
                category.Description = category.Description;

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

            using (var context = new openTillEntities())
            {
                // Throws an exception if a brand with the given name already exists
                if (context.Brands.SingleOrDefault(b => b.Name == newBrand.Name) != null)
                    throw new InvalidOperationException("A brand with the given brand name already exists.");

                context.Brands.Add(Mapper.Map<Brand>(newBrand));
                context.SaveChanges();
            }
        }
        /// <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>
        /// Deletes a brand.
        /// </summary>
        /// <param name="brandDel">Brand to delete</param>
        public void Delete(BrandDTO brandDel)
        {
            // Throws an an exception for a null dto
            if (brandDel == null)
                throw new ArgumentNullException("brandDel",
                    "brandDel does not accept a null dot as an argument.");

            using (var context = new openTillEntities())
            {
                var brand = context.Brands.SingleOrDefault(b => b.Id == brandDel.Id);

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

                context.Brands.Remove(brand);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Deletes a category.
        /// </summary>
        /// <param name="categoryDel">Category to delete</param>
        public void Delete(CategoryDTO categoryDel)
        {
            // Throws an exception for a null dto
            if (categoryDel == null)
                throw new ArgumentNullException("categoryDel",
                    "categoryDel does not accept a null dto as an argument.");

            using (var context = new openTillEntities())
            {
                var category = context.Categories.SingleOrDefault(c => c.Id == categoryDel.Id);

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

                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
Example #8
0
        /// <summary>
        /// Submits a new brand for persistence.
        /// </summary>
        /// <param name="newBrand">New brand to save.</param>
        public void Insert(BrandDTO newBrand)
        {
            // Throws an an exception for a null dto
            if (newBrand == null)
            {
                throw new ArgumentNullException("newBrand",
                                                "newBrand does not accept a null dot as an argument.");
            }

            using (var context = new openTillEntities())
            {
                // Throws an exception if a brand with the given name already exists
                if (context.Brands.SingleOrDefault(b => b.Name == newBrand.Name) != null)
                {
                    throw new InvalidOperationException("A brand with the given brand name already exists.");
                }

                context.Brands.Add(Mapper.Map <Brand>(newBrand));
                context.SaveChanges();
            }
        }
Example #9
0
        /// <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();
            }
        }
Example #10
0
        /// <summary>
        /// Submits a new category for persistence.
        /// </summary>
        /// <param name="newCategory">New category to save</param>
        public void Insert(CategoryDTO newCategory)
        {
            // Throws an exception for a null dto
            if (newCategory == null)
            {
                throw new ArgumentNullException("newCategory",
                                                "newCategory does not accept a null dto as an argument.");
            }

            using (var context = new openTillEntities())
            {
                // Throws an exception if a category with the given name already exists
                if (context.Categories.SingleOrDefault(c => c.Name == newCategory.Name) != null)
                {
                    throw new InvalidOperationException("A category with the given name already.");
                }

                context.Categories.Add(Mapper.Map <Category>(newCategory));
                context.SaveChanges();
            }
        }
Example #11
0
        /// <summary>
        /// Deletes a category.
        /// </summary>
        /// <param name="categoryDel">Category to delete</param>
        public void Delete(CategoryDTO categoryDel)
        {
            // Throws an exception for a null dto
            if (categoryDel == null)
            {
                throw new ArgumentNullException("categoryDel",
                                                "categoryDel does not accept a null dto as an argument.");
            }

            using (var context = new openTillEntities())
            {
                var category = context.Categories.SingleOrDefault(c => c.Id == categoryDel.Id);

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

                context.Categories.Remove(category);
                context.SaveChanges();
            }
        }
Example #12
0
        /// <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();
            }
        }
Example #13
0
        /// <summary>
        /// Deletes a brand.
        /// </summary>
        /// <param name="brandDel">Brand to delete</param>
        public void Delete(BrandDTO brandDel)
        {
            // Throws an an exception for a null dto
            if (brandDel == null)
            {
                throw new ArgumentNullException("brandDel",
                                                "brandDel does not accept a null dot as an argument.");
            }

            using (var context = new openTillEntities())
            {
                var brand = context.Brands.SingleOrDefault(b => b.Id == brandDel.Id);

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

                context.Brands.Remove(brand);
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Updates an existing category.
        /// </summary>
        /// <param name="categoryUpdate">Category to update</param>
        public void Update(CategoryDTO categoryUpdate)
        {
            // Throws an exception for a null dto
            if (categoryUpdate == null)
                throw new ArgumentNullException("categoryUpdate",
                    "categoryUpdate does not accept a null dto as an argument.");

            using (var context = new openTillEntities())
            {
                var category = context.Categories.SingleOrDefault(c => c.Id == categoryUpdate.Id);

                // Throws an exception if the given category doesn't exist
                if (category == null)
                    throw new InvalidOperationException("No entry matching the given category was found.");

                // Throws an exception if a category with the given name already exists
                if (context.Categories.SingleOrDefault(c => c.Name == categoryUpdate.Name) != null)
                    throw new InvalidOperationException("A category with the given name already.");

                // Update existing category
                category.Name = categoryUpdate.Name;
                category.Description = category.Description;

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

            using (var context = new openTillEntities())
            {
                // Throws an exception if a category with the given name already exists
                if (context.Categories.SingleOrDefault(c => c.Name == newCategory.Name) != null)
                    throw new InvalidOperationException("A category with the given name already.");

                context.Categories.Add(Mapper.Map<Category>(newCategory));
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Updates an existing brand.
        /// </summary>
        /// <param name="brandUpdate">Brand to update</param>
        public void Update(BrandDTO brandUpdate)
        {
            // Throws an an exception for a null dto
            if (brandUpdate == null)
                throw new ArgumentNullException("brandUpdate",
                    "brandUpdate does not accept a null dot as an argument.");

            using (var context = new openTillEntities())
            {
                var brand = context.Brands.SingleOrDefault(b => b.Id == brandUpdate.Id);

                // Throws an exception if the given brand doesn't exist
                if (brand == null)
                    throw new InvalidOperationException("No entry matching the given brand was found.");

                // Throws an exception if a brand with the given name already exists
                if (context.Brands.SingleOrDefault(b => b.Name == brandUpdate.Name) != null)
                    throw new InvalidOperationException("A brand with the given brand name already exists.");

                // Update existing brand
                brand.Name = brandUpdate.Name;

                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>
        /// 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();
            }
        }