示例#1
0
        private TaxResponse ParseTaxLine(string line, int lineNR)
        {
            TaxResponse response = new TaxResponse();

            string[] columns = line.Split(_delimeter);
            if (columns.Length != Enum.GetNames(typeof(TaxFileHeaderElement)).Length)
            {
                response.Message = $"The data on line number {lineNR} in the file {TaxesFileName} is corrupt. \nContact IT!";
                response.Success = false;
                return(response);
            }

            bool     taxReadSuccess   = true;
            string   taxReadExMessage = $"The following elements on line number {lineNR} were not able to be parsed:\n";
            StateTax myStateTax       = new StateTax();

            //StateAbbreviation
            if (columns[(int)TaxFileHeaderElement.StateAbbreviation].All(c => char.IsLetterOrDigit(c) || char.IsWhiteSpace(c) || char.IsPunctuation(c)))
            {
                myStateTax.StateCode = columns[(int)TaxFileHeaderElement.StateAbbreviation];
            }
            else
            {
                taxReadExMessage += $"* StateAbbreviation\n";
                taxReadSuccess    = false;
            }
            //StateName
            if (columns[(int)TaxFileHeaderElement.StateName].All(c => char.IsLetterOrDigit(c) || char.IsWhiteSpace(c) || char.IsPunctuation(c)))
            {
                myStateTax.StateName = columns[(int)TaxFileHeaderElement.StateName];
            }
            else
            {
                taxReadExMessage += $"* StateName\n";
                taxReadSuccess    = false;
            }
            //TaxRate
            if (decimal.TryParse(columns[(int)TaxFileHeaderElement.TaxRate], out decimal parsedTaxRate))
            {
                myStateTax.TaxRate = parsedTaxRate;
            }
            else
            {
                taxReadExMessage += $"* TaxRate\n";
                taxReadSuccess    = false;
            }
            //Check if all elements were read w/o error
            if (taxReadSuccess)
            {
                response.Success  = true;
                response.StateTax = myStateTax;
                return(response);
            }
            else
            {
                response.Message = taxReadExMessage;
                response.Success = true;
                return(response);
            }
        }
        public StateTax GetStateTax(string stateTax)
        {
            StateTax taxState = new StateTax();

            using (StreamReader sr = new StreamReader(_filepath))
            {
                sr.ReadLine();

                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] splitLine = line.Split(',');

                    if (stateTax.Trim().ToUpper() == splitLine[0].Trim().ToUpper())
                    {
                        taxState.StateAbbreviation = splitLine[0];
                        taxState.StateName         = splitLine[1];
                        taxState.TaxRate           = decimal.Parse(splitLine[2]);

                        return(taxState);
                    }
                }
                return(null);
            }
        }
示例#3
0
        public List <StateTax> GetAllTaxes()
        {
            List <StateTax> allTaxes = new List <StateTax>();
            bool            exists   = File.Exists(getPath());

            if (exists)
            {
                string[] split;
                string   taxStr;
                using (var stream = File.OpenRead(getPath()))
                    using (var reader = new StreamReader(stream))
                    {
                        reader.ReadLine();
                        while (!reader.EndOfStream)
                        {
                            taxStr = reader.ReadLine();
                            split  = taxStr.Split(',');
                            string  state = split[0];
                            decimal tax;
                            decimal.TryParse(split[2], out tax);
                            StateTax st = new StateTax(state, tax);
                            allTaxes.Add(st);
                        }
                    }
            }
            return(allTaxes);
        }
        internal static void Run()
        {
            Order oldOrder = LookupOrder();

            string   name    = EditCustomerName(oldOrder.CustomerName);
            StateTax tax     = EditState(oldOrder.StateTax);
            Material product = EditProduct(oldOrder.Product);
            decimal  area    = EditArea(oldOrder.Area);

            Order newOrder = new Order(oldOrder, name, tax, product, area);

            Console.Clear();
            ConsoleIO.PrintOrder(newOrder, true);
            bool saveEditedOrder = ConsoleIO.ConsoleKeyConfirmationSwitch("Would you like to replace the old order with this updated order?", true);

            if (saveEditedOrder)
            {
                Console.Clear();
                Manager           manager      = ManagerFactory.Create();
                EditOrderResponse editResponse = manager.EditOrder(newOrder);

                if (editResponse.Success)
                {
                    Console.WriteLine("Order updated successfully.");
                }
                else
                {
                    Console.WriteLine(editResponse.Message);
                }
            }
            Console.Write("Press any key to continue...");
            Console.ReadKey();
        }
        public List <StateTax> ListStates()
        {
            List <StateTax> states = new List <StateTax>();

            if (File.Exists(_stateTaxFilePath))
            {
                using (StreamReader sr = new StreamReader(_stateTaxFilePath, true))
                {
                    sr.ReadLine();
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        StateTax stateInFile = new StateTax();

                        string[] columns = line.Split(',');

                        stateInFile.StateAbbreviation = columns[0];
                        stateInFile.StateName         = columns[1];
                        stateInFile.TaxRate           = decimal.Parse(columns[2]);

                        states.Add(stateInFile);
                    }
                }
            }

            return(states);
        }
示例#6
0
        public Response Execute(Request request)
        {
            Response response = new Response
            {
                Date = request.Date,
                Type = request.Type
            };

            List <Order> orders   = _orderRepository.LoadOrders(request.Date) ?? new List <Order>();
            Product      product  = _orderRepository.LoadProductData(request.Product);
            StateTax     stateTax = _orderRepository.LoadStateTaxData(request.State);

            if (request.Type != WorkflowType.Add)
            {
                throw new Exception($"Expected workflow type: \"{WorkflowType.Add}\"." +
                                    $" Actual workflow type in request: {request.Type}.");
            }

            if (request.Date < DateTime.Now.Date)
            {
                response.Success = false;
                response.Message = "Order cannot be added to a past date. Ending workflow...";
                return(response);
            }

            if (stateTax == null)
            {
                response.Success = false;
                response.Message = $"State {request.State} not found in database. Ending workflow...";
                return(response);
            }

            if (product == null)
            {
                response.Success = false;
                response.Message = $"Product {request.Product} not found in database. Ending workflow...";
                return(response);
            }

            Order currentOrder = new Order()
            {
                OrderNumber = GenerateOrderNumber(orders),
                Customer    = request.Customer,
                Area        = request.Area,
                Product     = product,
                StateTax    = stateTax,
                Total       = (product.CostPerSquareFoot
                               + product.LaborCostPerSquareFoot)
                              * request.Area
                              * (1 + (stateTax.TaxRate / 100))
            };

            orders.Add(currentOrder);
            _orderRepository.SaveOrders(request.Date, orders);

            response.Orders  = orders;
            response.Success = true;
            response.Message = "Order added successfully. Returning to Main Menu...";
            return(response);
        }
示例#7
0
        public TestOrderRepo()
        {
            Product  pd  = new Product("Wood", 10m, 19m);
            StateTax tax = new StateTax("IN", 3m);
            Order    o1  = new Order("Mary", pd, tax, 10m, new DateTime(01 / 01 / 2000));

            orders.Add(o1);
        }
示例#8
0
        public TestTaxRepo()
        {
            StateTax t1 = new StateTax("OH", 3.2m);
            StateTax t2 = new StateTax("IN", 2.0m);

            st.Add(t1);
            st.Add(t2);
        }
示例#9
0
        public void CanGetStateTaxList(string stateAbbreviation, string expectedValue)
        {
            FileStateTaxRepository repo = new FileStateTaxRepository(filePath);

            StateTax actualValue = repo.GetState(stateAbbreviation);

            Assert.IsNotNull(actualValue);
        }
示例#10
0
        public void GetTax()
        {
            IStateRepo  repo = new TestTaxRepo();
            TaxMgr      tm   = new TaxMgr(repo);
            TaxResponse resp = tm.GetTaxes("OH");
            StateTax    tax  = resp.StateTax;

            Assert.IsNotNull(tax);
        }
 public override string ToString()
 {
     return(Id + " "
            + FirstName + " "
            + LastName + " "
            + GrossPay.ToString("C") + " "
            + FederalTax.ToString("C") + " "
            + StateTax.ToString("C") + " "
            + NetPay.ToString("C"));
 }
        public void StateTaxRepoShouldReturnCorrectStateData(string expectedStateAbbreviation, string expectedStateName,
                                                             decimal expectedTaxRate, bool expectedResult)
        {
            IStateTaxRepository stateTaxRepository = new TestStateTaxRepository();

            StateTax stateTaxFromAbbreviation = stateTaxRepository.GetStateTax(expectedStateAbbreviation);
            StateTax stateTaxFromFullName     = stateTaxRepository.GetStateTax(expectedStateName);

            Assert.AreEqual(stateTaxFromAbbreviation, stateTaxFromFullName);
            Assert.AreEqual(expectedStateAbbreviation, stateTaxFromFullName.StateAbbreviation);
            Assert.AreEqual(expectedStateName, stateTaxFromFullName.StateName);
            Assert.AreEqual(expectedTaxRate, stateTaxFromFullName.TaxRate);
        }
示例#13
0
        public StateTax GetTaxes(string stateAbb)
        {
            StateTax tax = null;

            foreach (StateTax items in st)
            {
                if (items.StateAbb == stateAbb)
                {
                    tax = items;
                }
            }
            return(tax);
        }
示例#14
0
        public StateTax GetTaxes(string stateAbb)
        {
            StateTax        tax   = null;
            List <StateTax> taxes = GetAllTaxes();

            foreach (StateTax items in taxes)
            {
                if (items.StateAbb == stateAbb)
                {
                    tax = items;
                }
            }
            return(tax);
        }
        public StateTax GetState(string stateAbbr)
        {
            StateTax state = null;

            foreach (StateTax st in states)
            {
                if (stateAbbr == st.StateAbbreviation)
                {
                    state = st;
                }
            }

            return(state);
        }
示例#16
0
        private static StateTax mapStateTax(string line)
        {
            //var numStyle = NumberStyles.None;
            string acctType = "";

            string[] fields = line.Split(',');

            StateTax oneStateTax = new StateTax();

            oneStateTax.StateAbrev = fields[0];
            oneStateTax.StateName  = fields[1];
            oneStateTax.Tax        = Decimal.Parse(fields[2]);

            return(oneStateTax);
        }
        public void CanAddOrder()
        {
            InMemoryOrderRepo repo = new InMemoryOrderRepo();

            DateTime date    = new DateTime(2012, 5, 4);
            Material product = new Material("Wood", 2.50m, 4.50m);
            StateTax tax     = new StateTax("HI", "Hawaii", 15m);

            Order order = new Order(date, product, tax, "Bob", 150);

            repo.SaveOrder(order);

            var orders = repo.GetAllOrdersOnDate(new DateTime(2012, 5, 4));

            Assert.AreEqual(2, orders.Count());
        }
示例#18
0
        public TaxResponse GetTaxByState(string stateAbbr)
        {
            TaxResponse response = new TaxResponse();

            try
            {
                TaxesResponse responseTs = new TaxesResponse();
                responseTs = GetTaxes();
                if (responseTs.Success)
                {
                    StateTax statetaxToGet = responseTs.Taxes.Find(t => t.StateCode.ToUpper() == stateAbbr.ToUpper());
                    if (statetaxToGet == null)
                    {
                        response.Message = $"Was unable to find a state matching state abbreviation: {stateAbbr}!";
                        response.Success = false;
                        return(response);
                    }
                    else
                    {
                        response.Success  = true;
                        response.StateTax = statetaxToGet;
                        return(response);
                    }
                }
                else
                {
                    response.Message = responseTs.Message;
                    response.Success = false;
                    return(response);
                }
            }

            catch (FileNotFoundException)
            {
                response.Message = $"The file: {TaxesFileName} was not found. \nContact IT!";
                response.Success = false;
                return(response);
            }
            catch (Exception ex)
            {
                throw ex; //Throw exception up to calling method for handling in catch there.
            }

            finally
            {
            }
        }
示例#19
0
        private void btnNetPay_Click(object sender, EventArgs e)
        {
            double Hours, Rate;
            double GrossPay, FederalTax, StateTax, NetPay;

            Hours      = Convert.ToDouble(txtAmountWorked.Text);
            Rate       = Convert.ToDouble(txtHourlyDailyMonthlyRate.Text);
            GrossPay   = Hours * Rate;
            FederalTax = GrossPay * 0.15;
            StateTax   = GrossPay * 5 / 100;
            NetPay     = GrossPay - (FederalTax + StateTax);

            txtGrossPay.Text   = GrossPay.ToString("c");
            txtStateTax.Text   = StateTax.ToString("c");
            txtFederalTax.Text = FederalTax.ToString("c");
            txtNetPay.Text     = NetPay.ToString("c");
        }
示例#20
0
文件: TaxMgr.cs 项目: mikechowdiv/swg
        public TaxResponse GetTaxes(string stateAbb)
        {
            StateTax    tax  = repo.GetTaxes(stateAbb);
            TaxResponse resp = new TaxResponse();

            if (tax == null)
            {
                resp.Success = false;
                resp.Message = "Do not have tax info for this state...";
            }
            else
            {
                resp.Success  = true;
                resp.StateTax = tax;
            }
            return(resp);
        }
示例#21
0
        //public static List<StateTax> statesList = List(Settings.statesFilePath);

        public List<StateTax> ListOfStateTaxes()
        {
            List<StateTax> states = new List<StateTax>();
            using (StreamReader sr = new StreamReader(Settings.statesFilePath))
            {
                sr.ReadLine();
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    StateTax state = new StateTax();

                    string[] columns = line.Split(',');
                    state.StateAbbreviation = columns[0].ToUpper();
                    state.StateName = columns[1].ToUpper();
                    state.TaxRate = decimal.Parse(columns[2]);
                    states.Add(state);
                }
                return states;
            }
        }
示例#22
0
        public IActionResult Put([FromBody] StateTax model)
        {
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            var statetaxes = _context.StateTaxes.Where(st => st.StateTaxId == model.StateTaxId).FirstOrDefault();

            if (statetaxes == null)
            {
                return(NotFound(new { Error = String.Format("Record has not been found", model.StateTaxId) }));
            }


            statetaxes.TaxAmount = model.TaxAmount;

            _context.SaveChanges();

            return(Ok(statetaxes));
        }
示例#23
0
        public TaxResponse GetTaxByState(string stateAbbr)
        {
            TaxResponse response = new TaxResponse();

            //Find matching record, or return null
            //return
            StateTax lookedupTax = _taxes.Find(t => t.StateCode.ToUpper() == stateAbbr.ToUpper());

            if (lookedupTax != null && lookedupTax.StateCode.ToUpper() == stateAbbr.ToUpper())
            {
                response.Success  = true;
                response.StateTax = lookedupTax;
                return(response);
            }
            else
            {
                response.Message  = $"Could not find a tax rate for the state: {stateAbbr}!";
                response.StateTax = lookedupTax;
                return(response);
            }
        }
        public StateTax GetStateTax(string targetState)
        {
            StateTax tax = new StateTax();
            Regex pattern = new Regex(targetState + @"\,[A-Za-z]+,\d+(\.\d+)?", RegexOptions.IgnoreCase);

            try
            {
                using (StreamReader stream = new StreamReader(_filePath))
                {
                    while (!stream.EndOfStream)
                    {
                        string line = stream.ReadLine();
                        string[] columns = line.Split(',');

                        if (line.StartsWith("State")) continue;
                        
                        if (pattern.IsMatch(line))
                        {
                            tax.StateAbbreviation = columns[0].ToUpper();
                            tax.StateName         = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(columns[1].ToLower());
                            tax.TaxRate           = decimal.Parse(columns[2]);

                            return tax;
                        }
                    }
                }
                return null;
            }
            catch (IOException error)
            {
                _errorLog.Annotate($"{DateTime.Now} -- File I/O Error: {error.Message}");
                return null;
            }
            catch (Exception error)
            {
                _errorLog.Annotate($"{DateTime.Now} -- Unknown Error: {error.Message}");
                return null;
            }
        }
示例#25
0
        private void button1_Click(object sender, EventArgs e)
        {
            double hours, rate;
            double FederalTax, NetPay, StateTax, GrossPay;

            /* Console.Write("Please Enter the number of hours worked");
             * String input = Console.ReadLine();
             * double hours = double.Parse
             */
            hours = Convert.ToDouble(textBox_HoursWorked.Text);
            rate  = Convert.ToDouble(textBox_HourlyRate.Text);

            GrossPay   = hours * rate;
            FederalTax = GrossPay * 0.15;
            StateTax   = GrossPay * 0.05;
            NetPay     = GrossPay - (FederalTax + StateTax);

            textBoxGrossPay.Text = GrossPay.ToString("C");
            textBoxFedTax.Text   = FederalTax.ToString("C");
            textBoxStateTax.Text = StateTax.ToString("C");
            textBoxNetPay.Text   = NetPay.ToString("C");
        }
示例#26
0
        private static Order CalcRestofOrder(Order orderFromUsr)
        {
            //Keep lInq statements here.
            // Move others to the getter.
            //Order completedOrder = new Order();
            OrderTestRepo2 orderRepo = new OrderTestRepo2();

            //List<Order> allCrntOrders = orderRepo.LoadOrders();
            List <StateTax> allTaxInfo = TaxRepo.ReadFile();
            List <Product>  allPrducts = ProductRepo.ReadFile();

            StateTax stateTax = allTaxInfo.FirstOrDefault(t => t.StateAbrev == orderFromUsr.State);

            orderFromUsr.TaxRate = stateTax.Tax;

            Product crntProd = allPrducts.FirstOrDefault(p => p.ProductType == orderFromUsr.ProductType);

            orderFromUsr.CostPerSquareFoot      = crntProd.CostPerSquareFoot;
            orderFromUsr.LaborCostPerSquareFoot = crntProd.LaborCostPerSquareFoot;

            return(orderFromUsr);
        }
示例#27
0
        public static string AskForNewStateAbbr()
        {
            List <StateTax> TaxList = TaxRepo.ReadFile();

            foreach (StateTax tax in TaxList)
            {
                Console.WriteLine("  " + (TaxList.IndexOf(tax) + 1) + ". " + tax.StateName);
            }
            Console.WriteLine("Type the number of the state.");

            int userNumChoice = CommonIO.GetIntFromUser(0, TaxList.Count, -1);

            if (userNumChoice == -1)
            {
                // Users choose zero when selecting no state, which gets set to -1 in GetIntFromUser using offset
                return(null);
            }
            else
            {
                StateTax SelectedState = TaxList.ElementAt(userNumChoice);
                return(SelectedState.StateAbrev);
            }
        }
示例#28
0
        public IActionResult Post([FromBody] StateTax model)
        {
            if (model == null)
            {
                return(new StatusCodeResult(500));
            }

            StateTax statetaxes = _context.StateTaxes.Where(st => st.StateTaxId == model.StateTaxId).FirstOrDefault();

            if (statetaxes != null)
            {
                return(new BadRequestObjectResult("Record already exist"));
            }

            statetaxes = new StateTax {
                StateTaxId = model.StateTaxId, TaxAmount = model.TaxAmount
            };

            _context.StateTaxes.Add(statetaxes);
            _context.SaveChanges();

            return(Ok(statetaxes));
        }
        public List <StateTax> List()
        {
            List <StateTax> taxes = new List <StateTax>();

            using (StreamReader sr = new StreamReader(_filePath))
            {
                //Skip header
                sr.ReadLine();
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    StateTax stateTax = new StateTax();
                    string[] columns  = line.Split(',');

                    stateTax.StateAbbreviation = columns[0];
                    stateTax.StateName         = columns[1];
                    stateTax.TaxRate           = decimal.Parse(columns[2]);

                    taxes.Add(stateTax);
                }
            }
            return(taxes);
        }
示例#30
0
        static TestStateTaxRepository()
        {
            StateTaxes = new List <StateTax>();

            StateTax ny = new StateTax()
            {
                StateAbbreviation = "NY",
                StateName         = "New York",
                TaxRate           = 8.875m
            };

            StateTax az = new StateTax()
            {
                StateAbbreviation = "AZ",
                StateName         = "Arizona",
                TaxRate           = 5m
            };

            StateTax oh = new StateTax()
            {
                StateAbbreviation = "OH",
                StateName         = "Ohio",
                TaxRate           = 6.25m
            };

            StateTax ca = new StateTax()
            {
                StateAbbreviation = "CA",
                StateName         = "California",
                TaxRate           = 9.75m
            };

            StateTaxes.Add(ny);
            StateTaxes.Add(az);
            StateTaxes.Add(oh);
            StateTaxes.Add(ca);
        }