/// <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> /// 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> /// 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> /// Returns all brands. /// </summary> /// <returns>IEnumerable of BrandDTO</returns> public IEnumerable <BrandDTO> GetAll() { IEnumerable <BrandDTO> brands; using (var context = new openTillEntities()) { brands = Mapper.Map <IEnumerable <BrandDTO> >(context.Brands); } return(brands); }
/// <summary> /// Returns all brands. /// </summary> /// <returns>IEnumerable of BrandDTO</returns> public IEnumerable<BrandDTO> GetAll() { IEnumerable<BrandDTO> brands; using (var context = new openTillEntities()) { brands = Mapper.Map<IEnumerable<BrandDTO>>(context.Brands); } return brands; }
/// <summary> /// Returns all employees. /// </summary> /// <returns>IEnumerable of EmployeeDto</returns> public IEnumerable <EmployeeDTO> GetAll() { IEnumerable <EmployeeDTO> employees; using (var context = new openTillEntities()) { employees = Mapper.Map <IEnumerable <EmployeeDTO> >(context.Employees); } return(employees); }
/// <summary> /// Returns all categories. /// </summary> /// <returns>IEnumerable of CategoryDTO</returns> public IEnumerable<CategoryDTO> GetAll() { IEnumerable<CategoryDTO> categories; using (var context = new openTillEntities()) { categories = Mapper.Map<IEnumerable<CategoryDTO>>(context.Categories); } return categories; }
/// <summary> /// Returns all products. /// </summary> /// <returns>IEnumerable of ProductDTO</returns> public IEnumerable <ProductDTO> GetAll() { IEnumerable <ProductDTO> products; using (var context = new openTillEntities()) { products = Mapper.Map <IEnumerable <ProductDTO> >(context.Products); } return(products); }
/// <summary> /// Returns all employees. /// </summary> /// <returns>IEnumerable of EmployeeDto</returns> public IEnumerable<EmployeeDTO> GetAll() { IEnumerable<EmployeeDTO> employees; using (var context = new openTillEntities()) { employees = Mapper.Map<IEnumerable<EmployeeDTO>>(context.Employees); } return employees; }
/// <summary> /// Returns all products. /// </summary> /// <returns>IEnumerable of ProductDTO</returns> public IEnumerable<ProductDTO> GetAll() { IEnumerable<ProductDTO> products; using (var context = new openTillEntities()) { products = Mapper.Map<IEnumerable<ProductDTO>>(context.Products); } return products; }
/// <summary> /// Returns all categories. /// </summary> /// <returns>IEnumerable of CategoryDTO</returns> public IEnumerable <CategoryDTO> GetAll() { IEnumerable <CategoryDTO> categories; using (var context = new openTillEntities()) { categories = Mapper.Map <IEnumerable <CategoryDTO> >(context.Categories); } return(categories); }
/// <summary> /// Validates an employee by confirming that the given password matches the password associated with the given username. /// </summary> /// <param name="userName">String username</param> /// <param name="password">String password</param> /// <returns>Bool authenticated</returns> public bool ValidateUser(string userName, string password) { Employee employee; // Creates a guid for comparison using the given password var empGuid = new Guid(SHA256.Create().ComputeHash(Encoding.Unicode.GetBytes(password))); using (var context = new openTillEntities()) { // Looks for an employee with the given username and password(comparison made using guid) employee = context.Employees.SingleOrDefault(e => e.UserName == userName && e.PasswordHash == empGuid); } return employee != null; }
/// <summary> /// Validates an employee by confirming that the given password matches the password associated with the given username. /// </summary> /// <param name="userName">String username</param> /// <param name="password">String password</param> /// <returns>Bool authenticated</returns> public bool ValidateUser(string userName, string password) { Employee employee; // Creates a guid for comparison using the given password var empGuid = new Guid(SHA256.Create().ComputeHash(Encoding.Unicode.GetBytes(password))); using (var context = new openTillEntities()) { // Looks for an employee with the given username and password(comparison made using guid) employee = context.Employees.SingleOrDefault(e => e.UserName == userName && e.PasswordHash == empGuid); } return(employee != null); }
/// <summary> /// Returns all products that match the given brand. /// </summary> /// <param name="brand">String product brand</param> /// <returns>IEnumerable of ProductDTO</returns> public IEnumerable<ProductDTO> GetByBrand(string brand) { // Throws an exception for invalid brand value if (String.IsNullOrWhiteSpace(brand)) throw new ArgumentNullException("brand", "brand does not accept a null or empty string as an argument."); IEnumerable<ProductDTO> products; using (var context = new openTillEntities()) { products = Mapper.Map<IEnumerable<ProductDTO>>(context.Products.Where(p => p.Brand.Name == brand)); } return products; }
/// <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> /// Returns all products that match the given brand. /// </summary> /// <param name="brand">String product brand</param> /// <returns>IEnumerable of ProductDTO</returns> public IEnumerable <ProductDTO> GetByBrand(string brand) { // Throws an exception for invalid brand value if (String.IsNullOrWhiteSpace(brand)) { throw new ArgumentNullException("brand", "brand does not accept a null or empty string as an argument."); } IEnumerable <ProductDTO> products; using (var context = new openTillEntities()) { products = Mapper.Map <IEnumerable <ProductDTO> >(context.Products.Where(p => p.Brand.Name == brand)); } return(products); }
/// <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(); } }
/// <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> /// Returns a category with a name matching the given name. Returns a null category if no match is found. /// </summary> /// <param name="name">Category name</param> /// <returns>CategoryDTO</returns> public CategoryDTO GetByName(string name) { // Throws an exception for invalid name value if (String.IsNullOrWhiteSpace(name)) throw new ArgumentNullException("name", "name does not accept a null or empty string as an argument."); CategoryDTO category; using (var context = new openTillEntities()) { category = Mapper.Map<CategoryDTO>(context.Categories.SingleOrDefault(c => c.Name == name)); // Throws an exception if the given category doesn't exist if (category == null) throw new InvalidOperationException("No entry matching the given category was found."); } return category; }
/// <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> /// 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> /// 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 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(); } }
/// <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 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> /// Returns a product matching the given upc. If no matching product is found an empty product is returned. /// </summary> /// <param name="upc">String product upc</param> /// <returns>ProductDTO</returns> public ProductDTO GetByUPC(string upc) { // Throws an exception for invalid upc value if (String.IsNullOrWhiteSpace(upc)) { throw new ArgumentNullException("upc", "upc does not accept a null or empty string as an argument."); } ProductDTO product; using (var context = new openTillEntities()) { product = Mapper.Map <ProductDTO>(context.Products.SingleOrDefault(p => p.UPC == upc)); // Throws an exception if no matching product is fonud if (product == null) { throw new InvalidOperationException("No product with the given upc exists."); } } return(product); }
/// <summary> /// Returns a category with a name matching the given name. Returns a null category if no match is found. /// </summary> /// <param name="name">Category name</param> /// <returns>CategoryDTO</returns> public CategoryDTO GetByName(string name) { // Throws an exception for invalid name value if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException("name", "name does not accept a null or empty string as an argument."); } CategoryDTO category; using (var context = new openTillEntities()) { category = Mapper.Map <CategoryDTO>(context.Categories.SingleOrDefault(c => c.Name == name)); // Throws an exception if the given category doesn't exist if (category == null) { throw new InvalidOperationException("No entry matching the given category was found."); } } return(category); }
/// <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> /// Returns a product matching the given upc. If no matching product is found an empty product is returned. /// </summary> /// <param name="upc">String product upc</param> /// <returns>ProductDTO</returns> public ProductDTO GetByUPC(string upc) { // Throws an exception for invalid upc value if (String.IsNullOrWhiteSpace(upc)) throw new ArgumentNullException("upc", "upc does not accept a null or empty string as an argument."); ProductDTO product; using (var context = new openTillEntities()) { product = Mapper.Map<ProductDTO>(context.Products.SingleOrDefault(p => p.UPC == upc)); // Throws an exception if no matching product is fonud if (product == null) throw new InvalidOperationException("No product with the given upc exists."); } return product; }
/// <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> /// 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 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> /// 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(); } }