public IActionResult Index(TaxCalculateViewModel lendViewModel) { // update the database var postalCode = _postalCodeRepository.GetById(lendViewModel.SelectedPostalCodeId); var incomeTax = _incomeTaxRepository.GetFullIncomeTax(postalCode.IncomeTaxId); var result = TaxCalculatorServiceFactory.GetTaxCalculatorService( (DataContracts.TaxType)Enum.Parse(typeof(DataContracts.TaxType), incomeTax.IncomeTaxType)).Calculate(incomeTax, lendViewModel.TaxableIncome); TaxResultViewModel taxResultViewModel = new TaxResultViewModel() { TaxableIncome = lendViewModel.TaxableIncome, TaxAmount = result.TotalAmount, TaxType = incomeTax.IncomeTaxType }; var log = new TaxQueryLog() { DateQueried = DateTime.Now, PostCode = postalCode.PostCode, TaxableIncome = lendViewModel.TaxableIncome, TaxAmount = result.TotalAmount }; _taxQueryLogRepository.Create(log); return(RedirectToAction("TaxResult", taxResultViewModel)); }
public ActionResult Checkout() { // Render empty form on new page request TaxResultViewModel taxResultViewModel = new TaxResultViewModel(); // Populate error message used by client side validation taxResultViewModel.ErrorMessage = "Please correct the highlighted fields and try again."; return(View(taxResultViewModel)); }
public ActionResult Checkout(decimal orderTotal, string state, string zipCode, bool resetFlag = false) { TaxResultViewModel taxResultViewModel = new TaxResultViewModel(); // Reset the form to accept new data if requested by the user if (resetFlag) { // Populate error message used by client side validation taxResultViewModel.ErrorMessage = "Please correct the highlighted fields and try again."; return(View(taxResultViewModel)); } TaxRequest taxRequest = new TaxRequest(); // Assuming the store is located at this address, so this From Address is used in all tax calculations // This can be made configurable with additional form fields in the view taxRequest.FromCity = "New York"; taxRequest.FromCountry = "US"; taxRequest.FromState = "NY"; // taxRequest.FromStreet = "20 Cooper Square"; taxRequest.FromZip = "10003"; taxRequest.Amount = orderTotal; // Special Promotion: FREE SHIPPING on all orders winter 2021! taxRequest.ShippingAmount = 0; taxRequest.ToCountry = "US"; taxRequest.ToState = state; taxRequest.ToZip = zipCode; // Add From Address to Nexus Addresses taxRequest.NexusAddresses.Add(new NexusAddress() { Country = taxRequest.FromCountry, State = taxRequest.FromState, ZipCode = taxRequest.FromZip }); // Add To Address to Nexus Addresses taxRequest.NexusAddresses.Add(new NexusAddress() { Country = taxRequest.ToCountry, State = taxRequest.ToState, ZipCode = taxRequest.ToZip }); taxResultViewModel.OrderTotal = orderTotal; taxResultViewModel.State = state; taxResultViewModel.ZipCode = zipCode; // Call TaxCalculator taxResultViewModel.TaxResult = GetTaxResultForOrder(taxRequest); taxResultViewModel.OrderTotalWithTax = orderTotal + taxResultViewModel.TaxResult.TaxAmount; // Check for bad request // Likely due to state/zipcode mismatch if (taxResultViewModel.TaxResult.TaxRate == -1) { // Populate error message to display to user in case of bad request taxResultViewModel.ErrorMessage = "Sorry but there was a problem finding your tax rate, please check state and zipcode or try again later."; taxResultViewModel.BadRequest = true; } return(View(taxResultViewModel)); }
public IActionResult TaxResult(TaxResultViewModel taxResultViewModel) { return(View(taxResultViewModel)); }