Example #1
0
        public async Task <IActionResult> TaxRateAddEdit(string stripeTaxRateId = null)
        {
            if (string.IsNullOrWhiteSpace(stripeTaxRateId))
            {
                return(View(new TaxRateAddEditModel()));
            }

            var rate = await _taxRateRepository.GetByIdAsync(stripeTaxRateId);

            var model = new TaxRateAddEditModel()
            {
                StripeTaxRateId = stripeTaxRateId,
                Country         = rate.Country,
                State           = rate.State,
                PostalCode      = rate.PostalCode,
                Rate            = rate.Rate
            };

            return(View(model));
        }
Example #2
0
        public async Task <IActionResult> TaxRateAddEdit(TaxRateAddEditModel model)
        {
            var existingRateCheck = await _taxRateRepository.GetByLocationAsync(new TaxRate()
            {
                Country = model.Country, PostalCode = model.PostalCode
            });

            if (existingRateCheck.Any())
            {
                ModelState.AddModelError(nameof(model.PostalCode), "A tax rate already exists for this Country/Postal Code combination.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var taxRate = new TaxRate()
            {
                Id         = model.StripeTaxRateId,
                Country    = model.Country,
                State      = model.State,
                PostalCode = model.PostalCode,
                Rate       = model.Rate
            };

            if (!string.IsNullOrWhiteSpace(model.StripeTaxRateId))
            {
                await _paymentService.UpdateTaxRateAsync(taxRate);
            }
            else
            {
                await _paymentService.CreateTaxRateAsync(taxRate);
            }

            return(RedirectToAction("TaxRate"));
        }