/// <returns>A task that represents the asynchronous operation</returns>
        public async Task <IActionResult> TaxCategoryAdd(Models.Tax.TaxCategoryModel model)
        {
            //ensure that Avalara tax provider is active
            if (!await _taxPluginManager.IsPluginActiveAsync(AvalaraTaxDefaults.SystemName))
            {
                return(new NullJsonResult());
            }

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

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

            var taxCategory = new TaxCategory();

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

            //save tax code type as generic attribute
            if (!string.IsNullOrEmpty(model.TypeId) && !model.TypeId.Equals(Guid.Empty.ToString()))
            {
                await _genericAttributeService.SaveAttributeAsync(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute, model.TypeId);
            }

            return(Json(new { Result = true }));
        }
Пример #2
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> CategoryAdd(TaxCategoryModel model)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageTaxSettings))
            {
                return(AccessDeniedView());
            }

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

            var taxCategory = new TaxCategory();

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

            return(Json(new { Result = true }));
        }