public decimal GetCostPerSqFt(string productType) { List<Product> products = new List<Product>(); var reader = File.ReadAllLines(_prodFile); //i = 1 starts on line 1 not 0. for (int i = 1; i < reader.Length; i++) { var newProduct = new Product(); var columns = reader[i].Split(','); newProduct.ProductType = columns[0]; newProduct.CostPerSquareFoot = decimal.Parse(columns[1]); products.Add(newProduct); } var result = products.FirstOrDefault( p => string.Equals(p.ProductType, productType, StringComparison.CurrentCultureIgnoreCase)); return result?.CostPerSquareFoot ?? 0; }
public List<Product> ListAllProducts() { if (!File.Exists(FilePath)) throw new Exception("Product file was not found!"); var 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]; product.CostPerSquareFoot = decimal.Parse(columns[1]); product.LaborCostPerSquareFoot = decimal.Parse(columns[2]); products.Add(product); } return products; }
//calls CreateOrder and stores a Order in response. public void PopulateOrder(string formattedDate) { OrderOperations ops = new OrderOperations(); var response = new Response(); Order order = new Order(); bool isValid = false; decimal stateRate = 0; Console.ForegroundColor = ConsoleColor.Yellow; Console.Clear(); Console.WriteLine("\tEnter Account Information"); Console.WriteLine("\t----------------------"); Console.ForegroundColor = ConsoleColor.White; bool checkedInput = true; do { Console.Write("\tLast Name: "); order.LastName = Console.ReadLine(); if (order.LastName.Length <= 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\tThat was not a valid entry.\n\t Please enter a name..."); log.ErrorMessage = "That was not a valid name(name) UI:PopulateOrder/AddWorkflow...."; ops.CallingErrorLogRepository(log.ErrorMessage); checkedInput = false; continue; } checkedInput = ops.ValidateInput(order.LastName.ToCharArray()); if (checkedInput == false) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\tNo special characters in name are permitted.\n\t Please enter valid name"); log.ErrorMessage = "That was not a valid name(name) UI:PopulateOrder/AddWorkflow...."; ops.CallingErrorLogRepository(log.ErrorMessage); } else { checkedInput = true; } } while (checkedInput == false); do { Console.ForegroundColor = ConsoleColor.White; Console.Write("\tState: "); order.State = Console.ReadLine(); //string state = order.State; if (order.State.Length < 2) { Console.WriteLine("\tThat was not a valid entry.\n Please enter a state..."); log.ErrorMessage = "That was not a valid entry(state) UI:PopulateOrder/AddWorkflow...."; ops.CallingErrorLogRepository(log.ErrorMessage); } else { isValid = true; stateRate = ops.MatchState(order.State); if (stateRate == 0) { isValid = false; } } } while (!isValid); //setting tax rate based on state order.TaxRate = stateRate; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\tYour tax rate is {0}: ", order.TaxRate); //-------------PRODUCT----------------------- Product product = new Product(); do { Console.ForegroundColor = ConsoleColor.White; //Console.WriteLine(""); Console.Write("\tPlease enter a product type:\n\t\t Carpet, Laminate, Tile, Wood: "); order.ProductType = Console.ReadLine(); if (order.ProductType.Length > 8 || order.ProductType.Length < 1) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\tThat was not a valid entry.\n Please enter a product..."); log.ErrorMessage = "That was not a valid entry (product) UI:PopulateOrder...."; ops.CallingErrorLogRepository(log.ErrorMessage); } else { order.CostSqFt = ops.ReturnCostPerSquareFoot(order.ProductType); } } while (order.CostSqFt == 0);// is 0 Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\tYour cost per square foot is {0:c}: ", order.CostSqFt); // getting labor per square foot order.LaborSqFt = ops.LaborPerSquareFt(order.ProductType); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\tYour labor per square foot is {0:c}: ", order.LaborSqFt); // getting area do { Console.ForegroundColor = ConsoleColor.White; Console.Write("\tArea: "); string input = Console.ReadLine(); if (input.Length == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\tThat was not a valid entry.\n\t Please enter a Area..."); log.ErrorMessage = "That was not a valid Area(Area) UI:PopulateOrder/AddWorkflow...."; ops.CallingErrorLogRepository(log.ErrorMessage); order.Area = 0; continue; } order.Area = decimal.Parse(input); if (order.Area <= 0) { Console.WriteLine("\tYou need to get a bigger house!"); log.ErrorMessage = "That was not a valid area (area) UI:PopulateOrder...."; ops.CallingErrorLogRepository(log.ErrorMessage); } } while (order.Area <= 0); // getting material cost order.MaterialCost = ops.MaterialCost(order.ProductType, order.Area); Console.ForegroundColor = ConsoleColor.White; Console.Write("\tMaterial Cost: {0:c} ", order.MaterialCost); //getting labor cost Console.ForegroundColor = ConsoleColor.White; order.LaborCost = ops.LaborCost(order.ProductType, order.Area); Console.Write("\nLabor Cost: {0:c} ", order.LaborCost); //get tax Console.ForegroundColor = ConsoleColor.White; order.Tax = ops.Tax(order.State, order.MaterialCost); Console.Write("\nTax: {0:c} ", order.Tax); //get total Console.ForegroundColor = ConsoleColor.White; Console.Write("\nTotal: {0:c}", order.Total); order.Total = ops.Total(order.MaterialCost, order.Tax, order.LaborCost); Console.WriteLine(); ops.CreateOrder(order, formattedDate); Console.Clear(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\n\tHere is your new order information: \n"); DisplayOrderWorkflow dowf = new DisplayOrderWorkflow(); dowf.PrintOrderInformation(order); Console.ForegroundColor = ConsoleColor.White; }