public IActionResult TaxCategoryAdd(Models.Tax.TaxCategoryModel model) { //ensure that Avalara tax provider is active if (!_taxPluginManager.IsPluginActive(AvalaraTaxDefaults.SystemName)) { return(new NullJsonResult()); } if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(ErrorJson(ModelState.SerializeErrors())); } var taxCategory = new TaxCategory(); taxCategory = model.ToEntity(taxCategory); _taxCategoryService.InsertTaxCategory(taxCategory); //save tax code type as generic attribute if (!string.IsNullOrEmpty(model.TypeId) && !model.TypeId.Equals(Guid.Empty.ToString())) { _genericAttributeService.SaveAttribute(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute, model.TypeId); } return(Json(new { Result = true })); }
public IActionResult TaxCategoryAdd(Models.Tax.TaxCategoryModel model) { //ensure that Avalara tax provider is active if (!(_taxService.LoadActiveTaxProvider(_workContext.CurrentCustomer) is AvalaraTaxProvider)) { return(new NullJsonResult()); } if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(Json(new DataSourceResult { Errors = ModelState.SerializeErrors() })); } var taxCategory = new TaxCategory(); taxCategory = model.ToEntity(taxCategory); _taxCategoryService.InsertTaxCategory(taxCategory); //save tax code type as generic attribute if (!string.IsNullOrEmpty(model.TypeId) && !model.TypeId.Equals(Guid.Empty.ToString())) { _genericAttributeService.SaveAttribute(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute, model.TypeId); } return(new NullJsonResult()); }
/// <summary> /// Prepare paged tax category list model /// </summary> /// <param name="searchModel">Tax category search model</param> /// <returns>Tax category list model</returns> public override TaxCategoryListModel PrepareTaxCategoryListModel(TaxCategorySearchModel searchModel) { //ensure that Avalara tax provider is active if (!_taxPluginManager.IsPluginActive(AvalaraTaxDefaults.SystemName)) { return(base.PrepareTaxCategoryListModel(searchModel)); } if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get tax categories var taxCategories = _taxCategoryService.GetAllTaxCategories().ToPagedList(searchModel); //get tax types and define the default value var taxTypes = _cacheManager.Get(AvalaraTaxDefaults.TaxCodeTypesCacheKey, () => _avalaraTaxManager.GetTaxCodeTypes()) ?.Select(taxType => new { Id = taxType.Key, Name = taxType.Value }); var defaultType = taxTypes ?.FirstOrDefault(taxType => taxType.Name.Equals("Unknown", StringComparison.InvariantCultureIgnoreCase)) ?? taxTypes?.FirstOrDefault(); //prepare grid model var model = new Models.Tax.TaxCategoryListModel().PrepareToGrid(searchModel, taxCategories, () => { //fill in model values from the entity return(taxCategories.Select(taxCategory => { //fill in model values from the entity var taxCategoryModel = new Models.Tax.TaxCategoryModel { Id = taxCategory.Id, Name = taxCategory.Name, DisplayOrder = taxCategory.DisplayOrder }; //try to get previously saved tax code type and description var taxCodeType = taxTypes?.FirstOrDefault(type => type.Id.Equals(_genericAttributeService.GetAttribute <string>(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute) ?? string.Empty)) ?? defaultType; taxCategoryModel.Type = taxCodeType?.Name ?? string.Empty; taxCategoryModel.TypeId = taxCodeType?.Id ?? Guid.Empty.ToString(); taxCategoryModel.Description = _genericAttributeService .GetAttribute <string>(taxCategory, AvalaraTaxDefaults.TaxCodeDescriptionAttribute) ?? string.Empty; return taxCategoryModel; })); }); return(new TaxCategoryListModel { Data = model.Data, Draw = model.Draw, RecordsTotal = model.RecordsTotal, RecordsFiltered = model.RecordsFiltered }); }
public override IActionResult Categories(TaxCategorySearchModel searchModel) { //ensure that Avalara tax provider is active if (!_taxPluginManager.IsPluginActive(AvalaraTaxDefaults.SystemName)) { return(base.Categories(searchModel)); } if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedDataTablesJson()); } //get tax categories var taxCategories = _taxCategoryService.GetAllTaxCategories().ToPagedList(searchModel); //get tax types and define the default value var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(AvalaraTaxDefaults.TaxCodeTypesCacheKey); var taxTypes = _cacheManager.Get(cacheKey, () => _avalaraTaxManager.GetTaxCodeTypes()) ?.Select(taxType => new { Id = taxType.Key, Name = taxType.Value }); var defaultType = taxTypes ?.FirstOrDefault(taxType => taxType.Name.Equals("Unknown", StringComparison.InvariantCultureIgnoreCase)) ?? taxTypes?.FirstOrDefault(); //prepare grid model var model = new Models.Tax.TaxCategoryListModel().PrepareToGrid(searchModel, taxCategories, () => { //fill in model values from the entity return(taxCategories.Select(taxCategory => { //fill in model values from the entity var taxCategoryModel = new Models.Tax.TaxCategoryModel { Id = taxCategory.Id, Name = taxCategory.Name, DisplayOrder = taxCategory.DisplayOrder }; //try to get previously saved tax code type and description var taxCodeType = taxTypes?.FirstOrDefault(type => type.Id.Equals(_genericAttributeService.GetAttribute <string>(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute) ?? string.Empty)) ?? defaultType; taxCategoryModel.Type = taxCodeType?.Name ?? string.Empty; taxCategoryModel.TypeId = taxCodeType?.Id ?? Guid.Empty.ToString(); taxCategoryModel.Description = _genericAttributeService .GetAttribute <string>(taxCategory, AvalaraTaxDefaults.TaxCodeDescriptionAttribute) ?? string.Empty; return taxCategoryModel; })); }); return(Json(model)); }
/// <summary> /// Prepare paged tax category list model /// </summary> /// <param name="searchModel">Tax category search model</param> /// <returns>Tax category list model</returns> public override TaxCategoryListModel PrepareTaxCategoryListModel(TaxCategorySearchModel searchModel) { //ensure that Avalara tax provider is active if (!(_taxService.LoadActiveTaxProvider(_workContext.CurrentCustomer) is AvalaraTaxProvider)) { return(base.PrepareTaxCategoryListModel(searchModel)); } if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get tax categories var taxCategories = _taxCategoryService.GetAllTaxCategories(); //get tax types and define the default value var taxTypes = _cacheManager.Get(AvalaraTaxDefaults.TaxCodeTypesCacheKey, () => _avalaraTaxManager.GetTaxCodeTypes()) ?.Select(taxType => new { Id = taxType.Key, Name = taxType.Value }); var defaultType = taxTypes ?.FirstOrDefault(taxType => taxType.Name.Equals("Unknown", StringComparison.InvariantCultureIgnoreCase)) ?? taxTypes?.FirstOrDefault(); //prepare grid model var model = new TaxCategoryListModel { Data = taxCategories.PaginationByRequestModel(searchModel).Select(taxCategory => { //fill in model values from the entity var taxCategoryModel = new Models.Tax.TaxCategoryModel { Id = taxCategory.Id, Name = taxCategory.Name, DisplayOrder = taxCategory.DisplayOrder }; //try to get previously saved tax code type and description var taxCodeType = taxTypes?.FirstOrDefault(type => type.Id.Equals(_genericAttributeService.GetAttribute <string>(taxCategory, AvalaraTaxDefaults.TaxCodeTypeAttribute) ?? string.Empty)) ?? defaultType; taxCategoryModel.Type = taxCodeType?.Name ?? string.Empty; taxCategoryModel.TypeId = taxCodeType?.Id ?? Guid.Empty.ToString(); taxCategoryModel.Description = _genericAttributeService .GetAttribute <string>(taxCategory, AvalaraTaxDefaults.TaxCodeDescriptionAttribute) ?? string.Empty; return(taxCategoryModel); }), Total = taxCategories.Count }; return(model); }
public IActionResult TaxCategoryUpdate(Models.Tax.TaxCategoryModel model) { return(base.CategoryUpdate(model)); }
/// <returns>A task that represents the asynchronous operation</returns> public async Task <IActionResult> TaxCategoryUpdate(Models.Tax.TaxCategoryModel model) { return(await base.CategoryUpdate(model)); }