/// <summary> /// Attempts to add an order to the current IOrderRepository data /// </summary> /// <param name="customerName">The customer name</param> /// <param name="state">The state</param> /// <param name="productType">The product type</param> /// <param name="area">The sq ft area</param> /// <returns>A validated response</returns> public AddOrderResponse AddOrder(string customerName, string state, string productType, decimal area) { AddOrderResponse response = new AddOrderResponse(); DateTime date = ParseDate(response, OrderRepository.OrderDate); //If the date couldn't be parsed... if (response.ResponseType.Equals(ResponseType.Invalid)) { return(response); } TaxData tax = TaxRepository.GetByValue(state); Product product = ProductRepository.GetByValue(productType); if (tax == null) { response.ResponseType = ResponseType.Fail; response.Message = $"We can't sell to the state: {state}"; } else if (product == null) { response.ResponseType = ResponseType.Fail; response.Message = $"Product doesn't exist: {productType}"; } else if (!(date > DateTime.Now.Date)) { response.ResponseType = ResponseType.Fail; response.Message = $"Date must be later than today's date: {DateTime.Today.Date:MM/dd/yyyy}"; } else if (!ValidNameInput(customerName)) { response.ResponseType = ResponseType.Fail; response.Message = "Invalid customer name input."; } else if (area < 0) { response.ResponseType = ResponseType.Fail; response.Message = "Area value must be a positive decimal."; } else if (area < 100) { response.ResponseType = ResponseType.Fail; response.Message = "Area value must be 100 or higher."; } if (response.ResponseType != ResponseType.Fail && response.ResponseType != ResponseType.Invalid) { Order order = Order.CreateOrder(customerName, area, tax, product, OrderRepository.Data); OrderRepository.Add(order); response.Order = order; response.Date = date; response.ResponseType = ResponseType.Success; } else { if (OrderRepository.Data.Count <= 0) { FileManager.DeleteFile(FileManager.OrdersPath, date); } } return(response); }