public ActionResult Configure() { var taxCategories = _taxCategoryService.GetAllTaxCategories(); if (taxCategories.Count == 0) return Content("No tax categories can be loaded"); var model = new TaxRateListModel(); //tax categories foreach (var tc in taxCategories) model.AvailableTaxCategories.Add(new SelectListItem() { Text = tc.Name, Value = tc.Id.ToString() }); //countries var countries = _countryService.GetAllCountries(true); foreach (var c in countries) model.AvailableCountries.Add(new SelectListItem() { Text = c.Name, Value = c.Id.ToString() }); //states model.AvailableStates.Add(new SelectListItem() { Text = "*", Value = "0" }); var states = _stateProvinceService.GetStateProvincesByCountryId(countries.FirstOrDefault().Id); foreach (var s in states) model.AvailableStates.Add(new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }); //tax rates model.TaxRates = _taxRateService.GetAllTaxRates() .Select(x => { var m = new TaxRateModel() { Id = x.Id, TaxCategoryId = x.TaxCategoryId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, Percentage = x.Percentage, }; var tc = _taxCategoryService.GetTaxCategoryById(x.TaxCategoryId); m.TaxCategoryName = (tc != null) ? tc.Name : ""; var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; return m; }) .ToList(); return View("Nop.Plugin.Tax.CountryStateZip.Views.TaxCountryStateZip.Configure", model); }
public ActionResult RatesList(GridCommand command) { var taxRatesModel = _taxRateService.GetAllTaxRates() .Select(x => { var m = new TaxRateModel() { Id = x.Id, TaxCategoryId = x.TaxCategoryId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, Percentage = x.Percentage, }; var tc = _taxCategoryService.GetTaxCategoryById(x.TaxCategoryId); m.TaxCategoryName = (tc != null) ? tc.Name : ""; var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; return m; }) .ToList(); var model = new GridModel<TaxRateModel> { Data = taxRatesModel, Total = taxRatesModel.Count }; return new JsonResult { Data = model }; }
public ActionResult RateUpdate(TaxRateModel model, GridCommand command) { var taxRate = _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip == "*" ? null : model.Zip; taxRate.Percentage = model.Percentage; _taxRateService.UpdateTaxRate(taxRate); return RatesList(command); }
public ActionResult RatesList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) return Content("Access denied"); var records = _taxRateService.GetAllTaxRates(command.Page - 1, command.PageSize); var taxRatesModel = records .Select(x => { var m = new TaxRateModel() { Id = x.Id, StoreId = x.StoreId, TaxCategoryId = x.TaxCategoryId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, Percentage = x.Percentage, }; //store var store = _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Name : "*"; //tax category var tc = _taxCategoryService.GetTaxCategoryById(x.TaxCategoryId); m.TaxCategoryName = (tc != null) ? tc.Name : ""; //country var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; //state var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; return m; }) .ToList(); var gridModel = new DataSourceResult { Data = taxRatesModel, Total = records.TotalCount }; return Json(gridModel); }
public ActionResult RateUpdate(TaxRateModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) return Content("Access denied"); var taxRate = _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip == "*" ? null : model.Zip; taxRate.Percentage = model.Percentage; _taxRateService.UpdateTaxRate(taxRate); return new NullJsonResult(); }
public ActionResult RateUpdate(TaxRateModel model, GridCommand command) { if (!ModelState.IsValid) { return new JsonResult { Data = "error" }; } var taxRate = _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip; taxRate.Percentage = model.Percentage; _taxRateService.UpdateTaxRate(taxRate); return RatesList(command); }