public ActionResult RatesList(GridCommand command) { var taxRatesModel = _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(); var model = new GridModel <TaxRateModel> { Data = taxRatesModel, Total = taxRatesModel.Count }; return(new JsonResult { Data = model }); }
public async Task <Tout> Get <Tin, Tout>(Tin request) { try { TaxRateModel mapped = mapper.Map <Tin, TaxRateModel>(request); string zip = mapped.Zip; TaxRateModel queryObject = mapped; queryObject.Zip = string.Empty; string query = uriHelper.CreateQueryString(queryObject); var url = uriHelper.CreateUri(baseUrl, UrlConstants.Rates, zip, query); HttpResponseMessage response = await taxRateHttpClient.Client.GetAsync(url); string responseContent = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <Tout>(responseContent)); } catch (Exception ex) { Console.Write(ex); throw; } }
public async Task <TaxRateModel> GetTaxRates(TaxRateRequest request) { TaxJarRateResponse response = null; TaxRateModel mapped = mapper.Map <TaxRateModel>(request); if (request == null) { throw new ArgumentException(nameof(request), "Request cannot be null. Zip code is required."); } if (string.IsNullOrEmpty(request.Zip)) { throw new ArgumentException(nameof(request.Zip), "Zip Code is required."); } if (!string.IsNullOrEmpty(request.City) || !string.IsNullOrEmpty(request.State) || !string.IsNullOrEmpty(request.Street) || !string.IsNullOrEmpty(request.Country)) { response = await taxRepository.Get <TaxRateModel, TaxJarRateResponse>(mapped); } else { response = await taxRepository.Get <TaxJarRateResponse>(request.Zip); } return(mapper.Map <TaxRateModel>(response)); }
public async Task <IActionResult> RateUpdate(TaxRateModel model) { var taxRate = await _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip == "*" ? null : model.Zip; taxRate.Percentage = model.Percentage; await _taxRateService.UpdateTaxRate(taxRate); return(new NullJsonResult()); }
public ActionResult RateUpdate(TaxRateModel model, GridCommand command) { var taxRate = _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip == "*" ? null : model.Zip; taxRate.Percentage = model.Percentage; _taxRateService.UpdateTaxRate(taxRate); return(RatesList(command)); }
public async Task <TaxRateModel> AddTaxRate(TaxRateModel model) { TaxRateModel taxRateModel = null; try { ScheduleType stype; if (Enum.TryParse <ScheduleType>(model.ScheduleType, out stype)) { taxRateModel = new TaxRateModel(); taxRateModel.MunicipalityName = model.MunicipalityName; taxRateModel.ScheduleType = stype.ToString(); taxRateModel.Year = model.Year; taxRateModel.TaxRate = model.TaxRate; taxRateModel.StartDate = model.StartDate; taxRateModel.EndDate = model.EndDate; } if (taxRateModel != null) { bool isexist = false; switch (stype) { case ScheduleType.Daily: isexist = _taxRateRepository.IsExistDaily(taxRateModel); break; case ScheduleType.Weekly: isexist = _taxRateRepository.IsExistDaily(taxRateModel); break; case ScheduleType.Monthly: isexist = _taxRateRepository.IsExistDaily(taxRateModel); break; } if (!isexist) { await _taxRateRepository.AddScheduleTaxRate(taxRateModel); } else { taxRateModel = null; } } } catch (Exception ex) { throw ex; } return(taxRateModel); }
public async Task <IActionResult> RatesList(DataSourceRequest command) { if (!await _permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(Content("Access denied")); } var records = await _taxRateService.GetAllTaxRates(command.Page - 1, command.PageSize); var taxRatesModel = new List <TaxRateModel>(); foreach (var x in records) { var m = new TaxRateModel { Id = x.Id, StoreId = x.StoreId, TaxCategoryId = x.TaxCategoryId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, Percentage = x.Percentage, }; //store var store = await _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Name : "*"; //tax category var tc = await _taxCategoryService.GetTaxCategoryById(x.TaxCategoryId); m.TaxCategoryName = (tc != null) ? tc.Name : ""; //country var c = await _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; //state var s = await _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; taxRatesModel.Add(m); } var gridModel = new DataSourceResult { Data = taxRatesModel, Total = records.TotalCount }; return(Json(gridModel)); }
public ActionResult RatesList(GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(Content("Access denied")); } var records = _taxRateService.GetAllTaxRates(command.Page - 1, command.PageSize); var taxRatesModel = records .Select(x => { var m = new TaxRateModel() { Id = x.Id, StoreId = x.StoreId, TaxCategoryId = x.TaxCategoryId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, Percentage = x.Percentage, }; //store var store = _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Name : "*"; //tax category var tc = _taxCategoryService.GetTaxCategoryById(x.TaxCategoryId); m.TaxCategoryName = (tc != null) ? tc.Name : ""; //country var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; //state var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; return(m); }) .ToList(); var model = new GridModel <TaxRateModel> { Data = taxRatesModel, Total = records.TotalCount }; return(new JsonResult { Data = model }); }
public ActionResult RateUpdate(TaxRateModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(Content("Access denied")); } var taxRate = _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip == "*" ? null : model.Zip; taxRate.Percentage = model.Percentage; _taxRateService.UpdateTaxRate(taxRate); return(new NullJsonResult()); }
public async Task <TaxRateModel> AddScheduleTaxRate(TaxRateModel taxRateModel) { try { _municipalityTaxRateContext.tblTaxRates.Add(taxRateModel); await _municipalityTaxRateContext.SaveChangesAsync(); return(taxRateModel); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> RatesList(DataSourceRequest command) { var records = await _taxRateService.GetAllTaxRates(command.Page - 1, command.PageSize); var taxRatesModel = new List <TaxRateModel>(); foreach (var x in records) { var m = new TaxRateModel { Id = x.Id, StoreId = x.StoreId, TaxCategoryId = x.TaxCategoryId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = x.Zip, Percentage = x.Percentage, }; //store var store = await _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Shortcut : "*"; //tax category var tc = await _taxCategoryService.GetTaxCategoryById(x.TaxCategoryId); m.TaxCategoryName = (tc != null) ? tc.Name : ""; //country var c = await _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "Unavailable"; //state var s = c?.StateProvinces.FirstOrDefault(z => z.Id == x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; taxRatesModel.Add(m); } var gridModel = new DataSourceResult { Data = taxRatesModel, Total = records.TotalCount }; return(Json(gridModel)); }
public ActionResult RateUpdate(TaxRateModel model, GridCommand command) { if (!ModelState.IsValid) { return(new JsonResult { Data = "error" }); } var taxRate = _taxRateService.GetTaxRateById(model.Id); taxRate.Zip = model.Zip; taxRate.Percentage = model.Percentage; _taxRateService.UpdateTaxRate(taxRate); return(RatesList(command)); }
public async Task <ActionResult <TaxRateModel> > AddTaxRate(TaxRateModel taxRateModel) { try { var result = await _taxRateRepository.AddScheduleTaxRate(taxRateModel); if (result == null) { return(new ObjectResult("Either Record already exists or input values are wrong")); } } catch (Exception ex) { return(new ObjectResult(ex.Message)); } return(Ok(taxRateModel)); }
public IActionResult SaveTaxRate(TaxRateModel taxRateModel) { if (taxRateModel.TaxId <= 0 || _taxService.Count(x => x.Id == taxRateModel.TaxId) == 0) { return(NotFound()); } var taxRate = taxRateModel.Id > 0 ? _taxRateService.Get(taxRateModel.Id) : new TaxRate(); if (taxRate == null) { return(NotFound()); } _modelMapper.Map(taxRateModel, taxRate); _taxRateService.InsertOrUpdate(taxRate); return(R.Success.Result); }
public async Task <IActionResult> Get([FromBody] TaxRateRequest request) { try { if (string.IsNullOrEmpty(request.Zip)) { return(BadRequest("Zip is required")); } if (string.IsNullOrEmpty(request.Country)) { return(BadRequest("Country is required")); } TaxRateModel taxRate = await taxService.GetTaxRates(request); return(Ok(JsonConvert.SerializeObject(mapper.Map <TaxRateResponse>(taxRate)))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
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)); }
public bool IsExistDaily(TaxRateModel model) { return(_municipalityTaxRateContext.tblTaxRates.Any(d => d.MunicipalityName == model.MunicipalityName && d.StartDate == model.StartDate && d.ScheduleType == ScheduleType.Daily.ToString())); }