public void addProduct() { Products product = new ProductsBuilder("sdsdsa", false).Build(); index = repo.addProduct(product); Assert.IsTrue(index != 0); }
/// <summary> /// -- A - $1.25 for each unit or $3.00 for 3 units /// -- B - $4.25 for each unit /// -- C - $1.00 for each unit or $5.00 for 6 units /// -- D - $0.75 for each unit /// </summary> private ProductsBuilder SetupProducts() { var productsBuilder = new ProductsBuilder(); productsBuilder.AddProduct("A", 1.25m, 3, 3); productsBuilder.AddProduct("B", 4.25m); productsBuilder.AddProduct("C", 1.0m, 6, 5); productsBuilder.AddProduct("D", 0.75m); return(productsBuilder); }
private Products(ProductsBuilder builder) { this.productID = builder.GetProductID; this.productName = builder.GetProductName; this.supplierID = builder.GetSupplierID; this.categoryID = builder.GetCategoryID; this.quantityPerUnit = builder.GetQuantityPerUnit; this.unitPrice = builder.GetUnitPrice; this.unitsInStock = builder.GetUnitsInStock; this.unitsOnOrder = builder.GetUnitsOnOrder; this.reorderLevel = builder.GetReorderLevel; this.discontinued = builder.GetDiscontinued; }
public Products getProductById(int productID) { Products product = null; Connection conn = new Connection(); SqlConnection connection = conn.SqlConnection; SqlCommand selectCommand = new SqlCommand(); selectCommand.Connection = connection; selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.CommandText = "GetProductById"; selectCommand.Parameters.Add("@ProductID", SqlDbType.Int); selectCommand.Parameters["@ProductID"].Value = productID; { try { connection.Open(); SqlDataReader dataReader = selectCommand.ExecuteReader(); if (dataReader.HasRows) { dataReader.Read(); product = new ProductsBuilder(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetBoolean(9)) .SupplierID(dataReader.IsDBNull(2) ? (int?)null : dataReader.GetInt32(2)) .CategoryID(dataReader.IsDBNull(3) ? (int?)null : dataReader.GetInt32(3)) .QuantityPerUnit(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4)) .UnitPrice(dataReader.IsDBNull(5) ? (decimal?)null : dataReader.GetDecimal(5)) .UnitsInStock(dataReader.IsDBNull(6) ? (short?)null : dataReader.GetInt16(6)) .UnitsOnOrder(dataReader.IsDBNull(7) ? (short?)null : dataReader.GetInt16(7)) .ReorderLevel(dataReader.IsDBNull(8) ? (short?)null : dataReader.GetInt16(8)) .Build(); } dataReader.Close(); } catch (Exception exc) { logger.logError(DateTime.Now, "Error while trying to get Product with ProductID = " + productID + "."); MessageBox.Show(exc.Message); } finally { connection.Close(); } logger.logInfo(DateTime.Now, "GetProductById method has sucessfully invoked."); return(product); } }
private JObject GetDBData() { IBuilder shopsBuilder = new ShopsBuilder(this.configuration); var shops = shopsBuilder.BuildData(); IBuilder sellersBuilder = new SellersBuilder(this.configuration); var sellers = sellersBuilder.BuildData(); IBuilder customersBuilder = new CustomerBuilder(this.configuration); var customers = customersBuilder.BuildData(); IBuilder groupsBuilder = new GroupsBuilder(this.configuration); var groups = groupsBuilder.BuildData(); IBuilder productsBuilder = new ProductsBuilder(this.configuration); var products = productsBuilder.BuildData(); return(new JObject(shops, sellers, customers, groups, products)); }
public List <Products> getAllProducts() { List <Products> productsList = new List <Products>(); Connection conn = new Connection(); SqlConnection connection = conn.SqlConnection; using (SqlCommand command = new SqlCommand("select * from Products", connection)) { try { connection.Open(); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { Products product = new ProductsBuilder(dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetBoolean(9)) .SupplierID(dataReader.IsDBNull(2) ? (int?)null : dataReader.GetInt32(2)) .CategoryID(dataReader.IsDBNull(3) ? (int?)null : dataReader.GetInt32(3)) .QuantityPerUnit(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4)) .UnitPrice(dataReader.IsDBNull(5) ? (decimal?)null : dataReader.GetDecimal(5)) .UnitsInStock(dataReader.IsDBNull(6) ? (short?)null : dataReader.GetInt16(6)) .UnitsOnOrder(dataReader.IsDBNull(7) ? (short?)null : dataReader.GetInt16(7)) .ReorderLevel(dataReader.IsDBNull(8) ? (short?)null : dataReader.GetInt16(8)) .Build(); productsList.Add(product); } dataReader.Close(); } catch (Exception exc) { logger.logError(DateTime.Now, "Error while trying to get all Products."); MessageBox.Show(exc.Message); } logger.logInfo(DateTime.Now, "GetAllProducts method has sucessfully invoked."); return(productsList); } }