public virtual List<Product> GetAllProducts() { try { var reader = File.ReadAllLines(FilePath); for (int i = 1; i < reader.Length; i++) { var columns = reader[i].Split(','); var product = new Product(); product.ProductType = columns[0]; product.CostPerSquareFoot = decimal.Parse(columns[1]); product.LaborCostPerSquareFoot = decimal.Parse(columns[2]); Products.Add(product); } } catch (Exception ex) { Logger.Error(ex, "Product Repo - GetAllProducts"); } return Products; }
public Response() { Message = ""; Order = new Order(); Slip = new OrderSlip(); OrderList = new List<Order>(); State = new State(); Product = new Product(); }
public void CheckIfProductExistsTest(string productType, bool expected) { // arrange var product = new Product(); product.ProductType = productType; // act var response = ops.CheckIfProductExists(product); // assert Assert.AreEqual(expected, response.Success); }
public Product LoadFromCSVForTesting(string productCSV) { var columns = productCSV.Split(','); var product = new Product(); product.ProductType = columns[0]; product.CostPerSquareFoot = decimal.Parse(columns[1]); product.LaborCostPerSquareFoot = decimal.Parse(columns[2]); return product; }
public void GetProductTest(string productType, int indexOfProduct) { // arrange Product product = new Product(); product.ProductType = productType; // act var result = _repo.GetProduct(product); var actual = _repo.ToCSVForTesting(result); // assert Assert.AreEqual(_products[indexOfProduct], actual); }
public Order CalculateOrderTotals(Order Order, State state, Product product) { Logger.Info("Calculate order Totals called", "OrderOps - CalculateOrderTotals"); Order.CostPerSquareFoot = _productsRepository.GetProduct(product).CostPerSquareFoot; Order.LaborCostPerSquareFoot = _productsRepository.GetProduct(product).LaborCostPerSquareFoot; Order.TaxRate = _statesRepository.GetState(state).TaxRate; Order.LaborCost = Order.LaborCostPerSquareFoot * Order.Area; Order.MaterialCost = Order.CostPerSquareFoot * Order.Area; Order.Tax = (Order.MaterialCost + Order.LaborCost) * (Order.TaxRate / 100); Order.Total = Order.LaborCost + Order.MaterialCost + Order.Tax; return Order; }
public virtual Product GetProduct(Product product) { var productToReturn = new Product(); try { List<Product> products = GetAllProducts(); productToReturn = products.FirstOrDefault(p => p.ProductType.ToUpper() == product.ProductType.ToUpper()); } catch (Exception ex) { Logger.Error(ex, "Product Repo - GetProduct"); } return productToReturn; }
public Response CheckIfProductExists(Product productQuery) { Logger.Info("Check if product exists called", "RepoOps - CheckIfProductExists"); var product = _productsRepository.GetProduct(productQuery); if (product == null) { Logger.Warning("Product does not exist", "RepoOps - CheckIfProductExists"); _response.Success = false; return _response; } else { _response.Success = true; _response.Product = product; return _response; } }
public List<Product> GetProductsList() { string filePath = @"DataFiles\ProductData.txt"; List<Product> products = new List<Product>(); var reader = File.ReadAllLines(filePath); for (int i = 1; i < reader.Length; i++) { var columns = reader[i].Split(','); var product = new Product(); product.ProductType = columns[0].ToUpper(); product.CostPerSquareFoot = decimal.Parse(columns[1]); product.LaborCostPerSquareFoot = decimal.Parse(columns[2]); products.Add(product); } return products; }
public Order() { State = new State(); ProductType = new Product(); }
public override Product GetProduct(Product product) { List<Product> products = GetAllProducts(); return products.FirstOrDefault(p => p.ProductType.ToUpper() == product.ProductType.ToUpper()); }
public string ToCSVForTesting(Product product) { return String.Format("{0},{1},{2}", product.ProductType, product.CostPerSquareFoot, product.LaborCostPerSquareFoot); }
public void PromptProductTypeFromUser() { string productInput; string yesNoInput = ""; _productsList = _oops.FetchProductsList(); do { Console.Clear(); Console.WriteLine("Here is a list of our products:"); Console.WriteLine("-------------------------------"); foreach (var product in _productsList) { Console.WriteLine(" {0}:", product.ProductType); Console.WriteLine(" -Materials Rate: {0:c}/sqft", product.CostPerSquareFoot); Console.WriteLine(" -Labor Rate: {0:c}/sqft", product.LaborCostPerSquareFoot); Console.WriteLine(); } Console.WriteLine("-------------------------------"); Console.WriteLine(); Console.Write("Enter the Product Type you want to order: "); productInput = Console.ReadLine(); Console.WriteLine(); if (productInput == "") { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("You must enter a Product Type"); Console.WriteLine("Press ENTER to continue..."); Console.ResetColor(); Console.ReadLine(); } else { //Quick check to see if product type is in list before confirming it to the system var pChoice = new Product {ProductType = productInput}; if (_productsList.Contains(pChoice)) { do { Console.Write("Confirm {0}? (Y)es or (N)o: ", productInput.ToUpper()); yesNoInput = Console.ReadLine().ToUpper(); } while (yesNoInput != "Y" && yesNoInput != "N"); if (yesNoInput == "Y") { var response = _oops.FetchProductInfo(productInput); _orderInfo.ProductType = response.ProductInfo.ProductType; _orderInfo.CostPerSquareFoot = response.ProductInfo.CostPerSquareFoot; _orderInfo.LaborCostPerSquareFoot = response.ProductInfo.LaborCostPerSquareFoot; } } else { _errorResponse.ErrorTime = DateTime.Now; _errorResponse.ErrorSourceMethod = "Add Order Method"; _errorResponse.Message = "Product type is not in the database."; _errorResponse.Input = productInput; _oops.SubmitErrorToLog(_errorResponse); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("That product is not in the database."); Console.WriteLine("Press ENTER to continue..."); Console.ResetColor(); Console.ReadLine(); } } } while (yesNoInput != "Y"); }
public Response ValidateProductType(string productTypeInput) { Product productQuery = new Product(); switch (productTypeInput) { case "C": productQuery.ProductType = "CARPET"; Response.Success = true; Response.Message = ""; Response.Product = productQuery; break; case "L": productQuery.ProductType = "LAMINATE"; Response.Success = true; Response.Message = ""; Response.Product = productQuery; break; case "T": productQuery.ProductType = "TILE"; Response.Success = true; Response.Message = ""; Response.Product = productQuery; break; case "W": productQuery.ProductType = "WOOD"; Response.Success = true; Response.Message = ""; Response.Product = productQuery; break; default: Response.Success = false; Response.Message = "That was not a valid input. C, L, T, and W are the only valid inputs.\n"; Logger.Warning("Invalid user Input", "ValidateUserInputs - ValidateProductType"); break; } return Response; }