Beispiel #1
0
        public async Task <IActionResult> RatesByCountryStateZipList(ConfigurationModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings))
            {
                return(await AccessDeniedDataTablesJson());
            }

            var records = await _taxRateService.GetAllTaxRatesAsync(searchModel.Page - 1, searchModel.PageSize);

            var gridModel = await new CountryStateZipListModel().PrepareToGridAsync(searchModel, records, () =>
            {
                return(records.SelectAwait(async record => new CountryStateZipModel
                {
                    Id = record.Id,
                    StoreId = record.StoreId,
                    StoreName = (await _storeService.GetStoreByIdAsync(record.StoreId))?.Name ?? "*",
                    TaxCategoryId = record.TaxCategoryId,
                    TaxCategoryName = (await _taxCategoryService.GetTaxCategoryByIdAsync(record.TaxCategoryId))?.Name ?? string.Empty,
                    CountryId = record.CountryId,
                    CountryName = (await _countryService.GetCountryByIdAsync(record.CountryId))?.Name ?? "Unavailable",
                    StateProvinceId = record.StateProvinceId,
                    StateProvinceName = (await _stateProvinceService.GetStateProvinceByIdAsync(record.StateProvinceId))?.Name ?? "*",

                    Zip = !string.IsNullOrEmpty(record.Zip) ? record.Zip : "*",
                    Percentage = record.Percentage
                }));
            });

            return(Json(gridModel));
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public override async Task <IActionResult> CategoryDelete(int id)
        {
            //ensure that Avalara tax provider is active
            if (!await _taxPluginManager.IsPluginActiveAsync(AvalaraTaxDefaults.SystemName))
            {
                return(new NullJsonResult());
            }

            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings))
            {
                return(AccessDeniedView());
            }

            //try to get a tax category with the specified id
            var taxCategory = await _taxCategoryService.GetTaxCategoryByIdAsync(id);

            if (taxCategory == null)
            {
                throw new ArgumentException("No tax category found with the specified id");
            }

            //delete generic attributes
            await _genericAttributeService.SaveAttributeAsync <string>(taxCategory, AvalaraTaxDefaults.TaxCodeDescriptionAttribute, null);

            await _genericAttributeService.SaveAttributeAsync <string>(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute, null);

            await _taxCategoryService.DeleteTaxCategoryAsync(taxCategory);

            return(new NullJsonResult());
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> CategoryUpdate(TaxCategoryModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(ErrorJson(ModelState.SerializeErrors()));
            }

            var taxCategory = await _taxCategoryService.GetTaxCategoryByIdAsync(model.Id);

            taxCategory = model.ToEntity(taxCategory);
            await _taxCategoryService.UpdateTaxCategoryAsync(taxCategory);

            return(new NullJsonResult());
        }