コード例 #1
0
        private void PrepareModel(ByRegionTaxRateListModel model)
        {
            var taxCategories  = _taxCategoryService.GetAllTaxCategories().ToDictionary(x => x.Id);
            var taxRates       = _taxRateService.GetAllTaxRates();
            var countries      = _countryService.GetAllCountries(true).ToDictionary(x => x.Id);
            var stateProvinces = _stateProvinceService.GetAllStateProvinces(true).ToDictionary(x => x.Id);
            var stateProvincesOfFirstCountry = stateProvinces.Values.Where(x => x.CountryId == countries.Values.FirstOrDefault().Id).ToList();
            var unavailable = T("Common.Unavailable").Text;

            model.AvailableTaxCategories = taxCategories.Values.Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.Id.ToString()
            })
                                           .ToList();

            model.AvailableCountries = countries.Values.Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.Id.ToString()
            })
                                       .ToList();

            model.AvailableStates = stateProvincesOfFirstCountry.Select(x => new SelectListItem
            {
                Text  = x.Name,
                Value = x.Id.ToString()
            })
                                    .ToList();
            model.AvailableStates.Insert(0, new SelectListItem {
                Text = "*", Value = "0"
            });

            model.TaxRates = taxRates.Select(x =>
            {
                var m = new ByRegionTaxRateModel
                {
                    Id              = x.Id,
                    TaxCategoryId   = x.TaxCategoryId,
                    CountryId       = x.CountryId,
                    StateProvinceId = x.StateProvinceId,
                    Zip             = x.Zip.HasValue() ? x.Zip : "*",
                    Percentage      = x.Percentage
                };

                taxCategories.TryGetValue(x.TaxCategoryId, out TaxCategory tc);
                m.TaxCategoryName = tc?.Name.EmptyNull();

                countries.TryGetValue(x.CountryId, out Country c);
                m.CountryName = c?.Name ?? unavailable;

                stateProvinces.TryGetValue(x.StateProvinceId, out StateProvince s);
                m.StateProvinceName = s?.Name ?? "*";

                return(m);
            })
                             .ToList();
        }
コード例 #2
0
        public ActionResult Configure()
        {
            var model = new ByRegionTaxRateListModel();

            PrepareModel(model);

            if (!model.AvailableTaxCategories.Any())
            {
                NotifyWarning(T("Plugins.Tax.CountryStateZip.NoTaxCategoriesFound"));
            }

            return(View(model));
        }
コード例 #3
0
        public ActionResult RatesList(GridCommand command)
        {
            var model = new ByRegionTaxRateListModel();

            PrepareModel(model);

            var data = new GridModel <ByRegionTaxRateModel>
            {
                Data  = model.TaxRates,
                Total = model.TaxRates.Count
            };

            return(new JsonResult
            {
                Data = data
            });
        }
コード例 #4
0
        public ActionResult AddTaxRate(ByRegionTaxRateListModel 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());
        }
コード例 #5
0
        public ActionResult AddTaxByRegionRecord(ByRegionTaxRateListModel 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);

            NotifySuccess(T("Plugins.Tax.CountryStateZip.AddNewRecord.Success"));
            return(Json(new { Result = true }));
        }
コード例 #6
0
        public ActionResult Configure()
        {
            var taxCategories = _taxCategoryService.GetAllTaxCategories();

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

            var model = new ByRegionTaxRateListModel();

            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 ByRegionTaxRateModel()
                {
                    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(model));
        }
コード例 #7
0
 public ActionResult Configure(ByRegionTaxRateListModel model)
 {
     return(Configure());
 }