Exemplo n.º 1
0
        public ActionResult Configure()
        {
            var taxCategories = _taxCategoryService.GetAllTaxCategories();

            if (taxCategories.Count == 0)
            {
                return(Content("No tax categories can be loaded"));
            }

            var model = new TaxRateListModel();

            //stores
            model.AvailableStores.Add(new SelectListItem()
            {
                Text = "*", Value = "0"
            });
            var stores = _storeService.GetAllStores();

            foreach (var s in stores)
            {
                model.AvailableStores.Add(new SelectListItem()
                {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }
            //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()
                });
            }

            return(View("Nop.Plugin.Tax.CountryStateZip.Views.TaxCountryStateZip.Configure", model));
        }
        public async Task <IActionResult> Configure()
        {
            var taxCategories = await _taxCategoryService.GetAllTaxCategories();

            if (taxCategories.Count == 0)
            {
                return(Content("No tax categories can be loaded"));
            }

            var model = new TaxRateListModel();

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = "*", Value = ""
            });
            var stores = await _storeService.GetAllStores();

            foreach (var s in stores)
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }
            //tax categories
            foreach (var tc in taxCategories)
            {
                model.AvailableTaxCategories.Add(new SelectListItem {
                    Text = tc.Name, Value = tc.Id.ToString()
                });
            }
            //countries
            var countries = await _countryService.GetAllCountries(showHidden : 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 = ""
            });
            var defaultCountry = countries.FirstOrDefault();

            if (defaultCountry != null)
            {
                var states = await _stateProvinceService.GetStateProvincesByCountryId(defaultCountry.Id);

                foreach (var s in states)
                {
                    model.AvailableStates.Add(new SelectListItem {
                        Text = s.Name, Value = s.Id.ToString()
                    });
                }
            }

            return(View("~/Plugins/Tax.CountryStateZip/Views/TaxCountryStateZip/Configure.cshtml", model));
        }
        public async Task <IActionResult> AddTaxRate(TaxRateListModel model)
        {
            var taxRate = new TaxRate
            {
                StoreId         = model.AddStoreId,
                TaxCategoryId   = model.AddTaxCategoryId,
                CountryId       = model.AddCountryId,
                StateProvinceId = model.AddStateProvinceId,
                Zip             = model.AddZip,
                Percentage      = model.AddPercentage
            };
            await _taxRateService.InsertTaxRate(taxRate);

            return(Json(new { Result = true }));
        }
        public ActionResult AddTaxRate(TaxRateListModel model)
        {
            var taxRate = new TaxRate()
            {
                TaxCategoryId   = model.AddTaxCategoryId,
                CountryId       = model.AddCountryId,
                StateProvinceId = model.AddStateProvinceId,
                Zip             = model.AddZip,
                Percentage      = model.AddPercentage
            };

            _taxRateService.InsertTaxRate(taxRate);

            return(Json(new { Result = true }));
        }
Exemplo n.º 5
0
        public ActionResult AddTaxRate(TaxRateListModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            var taxRate = new TaxRate()
            {
                TaxCategoryId   = model.AddTaxCategoryId,
                CountryId       = model.AddCountryId,
                StateProvinceId = model.AddStateProvinceId,
                Zip             = model.AddZip,
                Percentage      = model.AddPercentage
            };

            _taxRateService.InsertTaxRate(taxRate);

            return(Configure());
        }
        public async Task <IActionResult> AddTaxRate(TaxRateListModel model)
        {
            if (!await _permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings))
            {
                return(Content("Access denied"));
            }

            var taxRate = new TaxRate
            {
                StoreId         = model.AddStoreId,
                TaxCategoryId   = model.AddTaxCategoryId,
                CountryId       = model.AddCountryId,
                StateProvinceId = model.AddStateProvinceId,
                Zip             = model.AddZip,
                Percentage      = model.AddPercentage
            };
            await _taxRateService.InsertTaxRate(taxRate);

            return(Json(new { Result = true }));
        }
Exemplo n.º 7
0
        public ActionResult Configure()
        {
            var taxCategories = _taxCategoryService.GetAllTaxCategories();

            if (taxCategories.Count == 0)
            {
                return(Content("No tax categories can be loaded"));
            }

            var model = new TaxRateListModel();

            foreach (var tc in taxCategories)
            {
                model.AvailableTaxCategories.Add(new SelectListItem()
                {
                    Text = tc.Name, Value = tc.Id.ToString()
                });
            }
            var countries = _countryService.GetAllCountries(true);

            foreach (var c in countries)
            {
                model.AvailableCountries.Add(new SelectListItem()
                {
                    Text = c.Name, Value = c.Id.ToString()
                });
            }
            model.AvailableStates.Add(new SelectListItem()
            {
                Text = "*", Value = "0"
            });
            var states = _stateProvinceService.GetStateProvincesByCountryId(countries.FirstOrDefault().Id);

            if (states.Count > 0)
            {
                foreach (var s in states)
                {
                    model.AvailableStates.Add(new SelectListItem()
                    {
                        Text = s.Name, Value = s.Id.ToString()
                    });
                }
            }

            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("SmartStore.Plugin.Tax.CountryStateZip.Views.TaxCountryStateZip.Configure", model));
        }