public ActionResult Edit(int Id) { if (!IsValidateId(Id)) { return(HttpNotFound()); } var stateProvince = _stateProvinceService.GetStateProvinceById(Id); if (stateProvince == null) { return(HttpNotFound()); } var model = new StateProvinceViewModel { Id = stateProvince.Id, Name = stateProvince.Name, CountryName = _countryService.GetCountryById(stateProvince.Id).Name, DisplayOrder = stateProvince.DisplayOrder, Published = stateProvince.Published, CountryId = stateProvince.CountryId, Abbreviation = stateProvince.Abbreviation, AvailableCountry = GetCountryList() }; return(View(model)); }
public ActionResult VungVeHome() { var model = new TuyenVeXeHomeModel(); model.TenTuyenXe1 = _stateProvinceService.GetStateProvinceById(TinhThanhConfig.HA_NOI).Name; model.tuyenxes1 = _vexeService.TuyenVeXeSearch(TinhThanhConfig.HA_NOI).Select(c => { var item = new TuyenVeXeModel(); TuyenVeXeToMode(c, item); return(item); }).ToList(); model.TenTuyenXe2 = _stateProvinceService.GetStateProvinceById(TinhThanhConfig.HO_CHI_MINH).Name; model.tuyenxes2 = _vexeService.TuyenVeXeSearch(TinhThanhConfig.HO_CHI_MINH).Select(c => { var item = new TuyenVeXeModel(); TuyenVeXeToMode(c, item); return(item); }).ToList(); model.TenTuyenXe3 = _stateProvinceService.GetStateProvinceById(TinhThanhConfig.DA_NANG).Name; model.tuyenxes3 = _vexeService.TuyenVeXeSearch(TinhThanhConfig.DA_NANG).Select(c => { var item = new TuyenVeXeModel(); TuyenVeXeToMode(c, item); return(item); }).ToList(); return(PartialView(model)); }
public virtual IActionResult StateEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries)) { return(AccessDeniedView()); } //try to get a state with the specified id var state = _stateProvinceService.GetStateProvinceById(id); if (state == null) { return(RedirectToAction("List")); } //try to get a country with the specified id var country = _countryService.GetCountryById(state.CountryId); if (country == null) { return(RedirectToAction("List")); } //prepare model var model = _countryModelFactory.PrepareStateProvinceModel(null, country, state); return(View(model)); }
//edit public virtual IActionResult StateEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries)) { return(AccessDeniedView()); } var sp = _stateProvinceService.GetStateProvinceById(id); if (sp == null) { //No state found with the specified id return(RedirectToAction("List")); } var model = sp.ToModel(); //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = sp.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
public IActionResult RateByWeightList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedKendoGridJson()); } var records = _shippingByWeightService.GetAll(command.Page - 1, command.PageSize); var sbwModel = records.Select(record => { var model = new ShippingByWeightModel { Id = record.Id, StoreId = record.StoreId, StoreName = _storeService.GetStoreById(record.StoreId)?.Name ?? "*", WarehouseId = record.WarehouseId, WarehouseName = _shippingService.GetWarehouseById(record.WarehouseId)?.Name ?? "*", ShippingMethodId = record.ShippingMethodId, ShippingMethodName = _shippingService.GetShippingMethodById(record.ShippingMethodId)?.Name ?? "Unavailable", CountryId = record.CountryId, CountryName = _countryService.GetCountryById(record.CountryId)?.Name ?? "*", StateProvinceId = record.StateProvinceId, StateProvinceName = _stateProvinceService.GetStateProvinceById(record.StateProvinceId)?.Name ?? "*", From = record.From, To = record.To, AdditionalFixedCost = record.AdditionalFixedCost, PercentageRateOfSubtotal = record.PercentageRateOfSubtotal, RatePerWeightUnit = record.RatePerWeightUnit, LowerWeightLimit = record.LowerWeightLimit, Zip = !string.IsNullOrEmpty(record.Zip) ? record.Zip : "*" }; var htmlSb = new StringBuilder("<div>"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.From"), model.From); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.To"), model.To); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.AdditionalFixedCost"), model.AdditionalFixedCost); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.RatePerWeightUnit"), model.RatePerWeightUnit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.LowerWeightLimit"), model.LowerWeightLimit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.FixedOrByWeight.Fields.PercentageRateOfSubtotal"), model.PercentageRateOfSubtotal); htmlSb.Append("</div>"); model.DataHtml = htmlSb.ToString(); return(model); }).ToList(); var gridModel = new DataSourceResult { Data = sbwModel, Total = records.TotalCount }; return(Json(gridModel)); }
public ActionResult RatesList(GridCommand command) { var records = _shippingByWeightService.GetAll(command.Page - 1, command.PageSize); var sbwModel = records.Select(x => { var m = new ShippingByWeightModel() { Id = x.Id, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, From = x.From, To = x.To, AdditionalFixedCost = x.AdditionalFixedCost, PercentageRateOfSubtotal = x.PercentageRateOfSubtotal, RatePerWeightUnit = x.RatePerWeightUnit, LowerWeightLimit = x.LowerWeightLimit, }; var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "*"; var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; var htmlSb = new StringBuilder("<div>"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.From"), m.From); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.To"), m.To); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.AdditionalFixedCost"), m.AdditionalFixedCost); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.RatePerWeightUnit"), m.RatePerWeightUnit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.LowerWeightLimit"), m.LowerWeightLimit); htmlSb.Append("<br />"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.ByWeight.Fields.PercentageRateOfSubtotal"), m.PercentageRateOfSubtotal); htmlSb.Append("</div>"); m.DataHtml = htmlSb.ToString(); return(m); }) .ToList(); var model = new GridModel <ShippingByWeightModel> { Data = sbwModel, Total = records.TotalCount }; return(new JsonResult { Data = model }); }
public ActionResult Update() { bool status = false; string message = ""; if (Request.Form.Count > 0) { var models = JsonConvert.DeserializeObject <List <StateProvinceWBModel> >(Request.Form[0]); if (models != null) { var model = models[0]; var stateProvince = _stateProvinceService.GetStateProvinceById(model.Id); if (stateProvince != null && stateProvince != null) { stateProvince.Name = model.Name; stateProvince.Abbreviation = model.Abbreviation; _stateProvinceService.UpdateStateProvince(stateProvince); var stateProvinceWBs = _stateProvinceWBService.GetStateProvinceWBsByStateProvinceId(stateProvince.Id); var postalCodes = new List <String>(); if (!String.IsNullOrEmpty(model.PostalCode)) { postalCodes = model.PostalCode.Split(',').ToList(); } if (stateProvinceWBs != null) { var nonList = stateProvinceWBs.Where(x => !postalCodes.Contains(x.PostalCode)).ToList(); if (nonList != null) { _stateProvinceWBService.Delete(nonList); } foreach (var postalCode in postalCodes) { if (_stateProvinceWBService.GetByPostalCodeAndProvinceID(postalCode, stateProvince.Id) == null) { var stateProvinceWB = new StateProvincePostalCode { Id = 0, PostalCode = postalCode, StateProvinceID = stateProvince.Id }; _stateProvinceWBService.Insert(stateProvinceWB); } } } } model = _stateProvinceWBService.GetStateProvinceWBModelByStateProvinceId(model.Id); return(Json(model)); } } return(Json(new { Status = status, Message = message })); }
public async Task <ActionResult <StateProvinceResource> > GetMusicById(int id) { var stateProvince = await _stateProvinceService.GetStateProvinceById(id); if (stateProvince == null) { return(NotFound()); } var stateProvinceResource = _mapper.Map <StateProvince, StateProvinceResource>(stateProvince); return(Ok(stateProvinceResource)); }
public ActionResult RateByDistrictList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(ErrorForKendoGridJson("Access denied")); } var records = _shippingByDistrictService.GetAll(command.Page - 1, command.PageSize); var sbdModel = records.Select(x => { var m = new ShippingByDistrictModel { Id = x.Id, StoreId = x.StoreId, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, AdditionalFixedCost = x.AdditionalFixedCost, }; //shipping method var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; //store var store = _storeService.GetStoreById(x.StoreId); m.StoreName = (store != null) ? store.Name : "*"; //country var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "*"; //state var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId); m.StateProvinceName = (s != null) ? s.Name : "*"; //zip m.Zip = (!String.IsNullOrEmpty(x.Zip)) ? x.Zip : "*"; var htmlSb = new StringBuilder("<div>"); htmlSb.AppendFormat("{0}: {1}", _localizationService.GetResource("Plugins.Shipping.RateByDistrict.Fields.AdditionalFixedCost"), m.AdditionalFixedCost); htmlSb.Append("</div>"); m.DataHtml = htmlSb.ToString(); return(m); }) .ToList(); var gridModel = new DataSourceResult { Data = sbdModel, Total = records.TotalCount }; return(Json(gridModel)); }
public async Task <ActionResult <SaveAddressResource> > CreateCountry([FromBody] SaveAddressResource saveAddressResource) { var address = _mapper.Map <SaveAddressResource, Address>(saveAddressResource); address.TypeAddress = await _typeAddressService.GetTypeAddressById(saveAddressResource.TypeAddressId); var city = await _cityService.GetCityByName(saveAddressResource.CityName); var stateProvince = await _stateProvinceService.GetStateProvinceById(saveAddressResource.StateId); if (city != null && city.StateProvinceId == stateProvince.Id) { address.City = city; address.CityId = city.Id; } else { var cityToAdd = new City(); cityToAdd.Name = saveAddressResource.CityName; cityToAdd.StateProvinceId = saveAddressResource.StateId; var cityAdded = await _cityService.CreateCity(cityToAdd); address.City = cityAdded; address.CityId = cityAdded.Id; } address.Status = 1; var addressAdded = await _addressService.CreateAddress(address); var addressCreated = await _addressService.GetAddressById(addressAdded.Id); var token = Request.Headers["Authorization"].ToString(); var user = new JwtSecurityTokenHandler().ReadJwtToken(token); var userId = new Guid(user.Claims.ToArray()[0].Value.ToString()); var userAddresListItem = new UserAddressList(); userAddresListItem.UserId = userId; userAddresListItem.AddressId = addressCreated.Id; userAddresListItem.Status = 1; var addressListItemCreated = await _userAddressListService.CreateUserAddressListItem(userAddresListItem); if (addressListItemCreated == null) { BadRequest(); } var addressResource = _mapper.Map <Address, AddressResource>(addressCreated); return(Ok(addressResource)); }
public IActionResult RatesByCountryStateZipList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedKendoGridJson()); } var records = _taxRateService.GetAllTaxRates(command.Page - 1, command.PageSize); var taxRatesModel = records.Select(record => new CountryStateZipModel { Id = record.Id, StoreId = record.StoreId, StoreName = _storeService.GetStoreById(record.StoreId)?.Name ?? "*", TaxCategoryId = record.TaxCategoryId, TaxCategoryName = _taxCategoryService.GetTaxCategoryById(record.TaxCategoryId)?.Name ?? string.Empty, CountryId = record.CountryId, CountryName = _countryService.GetCountryById(record.CountryId)?.Name ?? "Unavailable", StateProvinceId = record.StateProvinceId, StateProvinceName = _stateProvinceService.GetStateProvinceById(record.StateProvinceId)?.Name ?? "*", Zip = !string.IsNullOrEmpty(record.Zip) ? record.Zip : "*", Percentage = record.Percentage, }).ToList(); var gridModel = new DataSourceResult { Data = taxRatesModel, Total = records.TotalCount }; return(Json(gridModel)); }
public IActionResult RatesByCountryStateZipList(ConfigurationModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedDataTablesJson()); } var records = _taxRateService.GetAllTaxRates(searchModel.Page - 1, searchModel.PageSize); var gridModel = new CountryStateZipListModel().PrepareToGrid(searchModel, records, () => { return(records.Select(record => new CountryStateZipModel { Id = record.Id, StoreId = record.StoreId, StoreName = _storeService.GetStoreById(record.StoreId)?.Name ?? "*", TaxCategoryId = record.TaxCategoryId, TaxCategoryName = _taxCategoryService.GetTaxCategoryById(record.TaxCategoryId)?.Name ?? string.Empty, CountryId = record.CountryId, CountryName = _countryService.GetCountryById(record.CountryId)?.Name ?? "Unavailable", StateProvinceId = record.StateProvinceId, StateProvinceName = _stateProvinceService.GetStateProvinceById(record.StateProvinceId)?.Name ?? "*", Zip = !string.IsNullOrEmpty(record.Zip) ? record.Zip : "*", Percentage = record.Percentage })); }); return(Json(gridModel)); }
protected virtual void QuanHuyenModelPrepare(QuanHuyenModel model, QuanHuyen quanhuyen, bool isEdit) { if (quanhuyen != null) { model.Id = quanhuyen.Id; model.Ten = quanhuyen.Ten; model.Ma = quanhuyen.Ma; model.ProvinceID = quanhuyen.ProvinceID; var provinceinfo = _stateProvinceService.GetStateProvinceById(model.ProvinceID); model.TenTinh = provinceinfo.Name; } if (isEdit) { var states = _stateProvinceService.GetStateProvincesByCountryId(NhaXesController.CountryID); if (states.Count > 0) { foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.Name, Value = s.Id.ToString(), Selected = (s.Id == model.ProvinceID) }); } } } }
private void LoadingShipping(PostProcessPaymentRequest postProcessPaymentRequest, PaymentRequest payment) { payment.Shipping = new Shipping(); payment.Shipping.ShippingType = ShippingType.NotSpecified; Address adress = new Address(); adress.Complement = string.Empty; adress.District = string.Empty; adress.Number = string.Empty; if (postProcessPaymentRequest.Order.ShippingAddressId.HasValue) { var shippingAddress = _addressService.GetAddressById(postProcessPaymentRequest.Order.ShippingAddressId.Value); if (shippingAddress != null) { adress.City = shippingAddress.City; adress.Country = _countryService.GetCountryById(shippingAddress.CountryId ?? 0)?.Name ?? "*"; adress.PostalCode = shippingAddress.ZipPostalCode; adress.State = _stateProvinceService.GetStateProvinceById(shippingAddress.StateProvinceId ?? 0)?.Abbreviation ?? "*"; adress.Street = shippingAddress.Address1; adress.Number = "."; payment.Shipping.Address = adress; } } payment.Shipping.Cost = Math.Round(GetConvertedRate(postProcessPaymentRequest.Order.OrderShippingInclTax), 2); }
public IActionResult RatesList(ConfigurationModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings)) { return(AccessDeniedDataTablesJson()); } var records = _shippingByTotalService.GetAllShippingByTotalRecords(model.Page - 1, model.PageSize); var gridModel = new ShippingByTotalListModel().PrepareToGrid(model, records, () => { return(records.Select(record => { var sbtModel = new ShippingByTotalModel { Id = record.Id, StoreId = record.StoreId, WarehouseId = record.WarehouseId, ShippingMethodId = record.ShippingMethodId, CountryId = record.CountryId, DisplayOrder = record.DisplayOrder, From = record.From, To = record.To, UsePercentage = record.UsePercentage, ShippingChargePercentage = record.ShippingChargePercentage, ShippingChargeAmount = record.ShippingChargeAmount, }; // shipping method var shippingMethod = _shippingService.GetShippingMethodById(record.ShippingMethodId); sbtModel.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; // store var store = _storeService.GetStoreById(record.StoreId); sbtModel.StoreName = (store != null) ? store.Name : "*"; // warehouse var warehouse = _shippingService.GetWarehouseById(record.WarehouseId); sbtModel.WarehouseName = (warehouse != null) ? warehouse.Name : "*"; // country var c = _countryService.GetCountryById(record.CountryId); sbtModel.CountryName = (c != null) ? c.Name : "*"; sbtModel.CountryId = record.CountryId; // state/province var s = _stateProvinceService.GetStateProvinceById(record.StateProvinceId); sbtModel.StateProvinceName = (s != null) ? s.Name : "*"; sbtModel.StateProvinceId = record.StateProvinceId; // ZIP / postal code sbtModel.ZipPostalCode = (!string.IsNullOrEmpty(record.ZipPostalCode)) ? record.ZipPostalCode : "*"; return sbtModel; })); }); return(Json(gridModel)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var stateProvince = _stateProvinceService.GetStateProvinceById(id.Value); if (stateProvince == null) { return(HttpNotFound()); } var stateProvinceVm = Mapper.Map <StateProvince, StateProvinceViewModel>(stateProvince); stateProvinceVm.Countries = new SelectList(_countryService.GetAllCountries(), "Id", "Name", stateProvinceVm.CountryId); return(View(stateProvinceVm)); }
public ActionResult StateEditPopup(int id) { var sp = _stateProvinceService.GetStateProvinceById(id); if (sp == null) { return(RedirectToAction("List")); } var model = sp.ToModel(); AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = sp.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
//edit public async Task <IActionResult> StateEditPopup(string id) { var sp = await _stateProvinceService.GetStateProvinceById(id); if (sp == null) { //No state found with the specified id return(RedirectToAction("List")); } var model = sp.ToModel(); //locales await AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = sp.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
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 async Task <LiquidVendor> Handle(GetVendorTokensCommand request, CancellationToken cancellationToken) { var liquidVendor = new LiquidVendor(request.Vendor); liquidVendor.StateProvince = !string.IsNullOrEmpty(request.Vendor.Address?.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(request.Vendor.Address.StateProvinceId))? .GetLocalized(x => x.Name, request.Language.Id) : ""; liquidVendor.Country = !string.IsNullOrEmpty(request.Vendor.Address?.CountryId) ? (await _countryService.GetCountryById(request.Vendor.Address.CountryId))? .GetLocalized(x => x.Name, request.Language.Id) : ""; return(liquidVendor); }
public ActionResult Create(VendorModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageVendors)) { return(AccessDeniedView()); } if (ModelState.IsValid) { var vendor = model.ToEntity(); //fill latitude and longitude from address if (vendor.StreetAddress != null && vendor.StreetAddress != "") { var city = _cityService.GetCityById(vendor.CityId.Value); vendor.StateId = city.StateId; var state = _stateProvinceService.GetStateProvinceById(vendor.StateId.Value); vendor.CountryId = state.CountryId; GoogleLocationService locservice = new GoogleLocationService(); MapPoint point = locservice.GetLatLongFromAddress(vendor.StreetAddress + ", " + city.CityName + ", " + state.Abbreviation + " " + city.PostCode); vendor.Latitude = point.Latitude; vendor.Longitude = point.Longitude; } _vendorService.InsertVendor(vendor); //search engine name model.SeName = vendor.ValidateSeName(model.SeName, vendor.Name, true); _urlRecordService.SaveSlug(vendor, model.SeName, 0); //locales UpdateLocales(vendor, model); SuccessNotification(_localizationService.GetResource("Admin.Vendors.Added")); return(continueEditing ? RedirectToAction("Edit", new { id = vendor.Id }) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult ConditionsList(GridCommand command) { var records = _freeShippingByOrderTotalService.GetAll(command.Page - 1, command.PageSize); var sbwModel = records.Select(x => { var m = new ShippingFreeOrdersOverModel() { Id = x.Id, CountryId = x.CountryId, OrderOver = x.OrderOver, StateProvinceId = x.StateProvinceId, ShippingMethodId = x.ShippingMethodId, }; var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId); m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable"; var c = _countryService.GetCountryById(x.CountryId); m.CountryName = (c != null) ? c.Name : "*"; 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 <ShippingFreeOrdersOverModel> { Data = sbwModel, Total = records.TotalCount }; return(new JsonResult { Data = model }); }
public IActionResult TestTaxRequest(ConfigurationModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageTaxSettings)) { return(AccessDeniedView()); } if (!ModelState.IsValid) { return(Configure()); } var taxProvider = _taxPluginManager.LoadPluginBySystemName(AvalaraTaxDefaults.SystemName) as AvalaraTaxProvider; //get result var transaction = taxProvider.CreateEstimatedTaxTransaction(new Address { City = model.TestAddress?.City, Country = _countryService.GetCountryById(model.TestAddress?.CountryId ?? 0), Address1 = model.TestAddress?.Address1, ZipPostalCode = model.TestAddress?.ZipPostalCode, StateProvince = _stateProvinceService.GetStateProvinceById(model.TestAddress?.StateProvinceId ?? 0) }, _workContext.CurrentCustomer.Id.ToString()); if (transaction?.totalTax != null) { //display tax rates by jurisdictions model.TestTaxResult = $"Total tax rate: {transaction.totalTax:0.00}% {Environment.NewLine}"; if (transaction.summary?.Any() ?? false) { model.TestTaxResult = transaction.summary.Aggregate(model.TestTaxResult, (resultString, rate) => $"{resultString}Jurisdiction: {rate?.jurisName}, Tax rate: {((rate?.rate ?? 0) * 100):0.00}% {Environment.NewLine}"); } _notificationService.SuccessNotification(_localizationService.GetResource("Plugins.Tax.Avalara.TestTax.Success")); } else { _notificationService.ErrorNotification(_localizationService.GetResource("Plugins.Tax.Avalara.TestTax.Error")); } //prepare model model.IsConfigured = IsConfigured(); PrepareAddress(model.TestAddress); PrepareLogModel(model.TaxTransactionLogSearchModel); model.HideGeneralBlock = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, AvalaraTaxDefaults.HideGeneralBlock); model.HideLogBlock = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, AvalaraTaxDefaults.HideLogBlock); return(View("~/Plugins/Tax.Avalara/Views/Configuration/Configure.cshtml", model)); }
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 static async Task <AddressModel> ToModel(this Address entity, ICountryService countryService = null, IStateProvinceService stateProvinceService = null) { var address = entity.MapTo <Address, AddressModel>(); if (!string.IsNullOrEmpty(address.CountryId) && countryService != null) { address.CountryName = (await countryService.GetCountryById(address.CountryId))?.Name; } if (!string.IsNullOrEmpty(address.StateProvinceId) && stateProvinceService != null) { address.StateProvinceName = (await stateProvinceService.GetStateProvinceById(address.StateProvinceId))?.Name; } return(address); }
/// <summary> /// Get models for shipping by total records /// </summary> public virtual IList <ByTotalModel> GetShippingByTotalModels(int pageIndex, int pageSize, out int totalCount) { // data join would be much better but not possible here cause ShippingByTotalObjectContext cannot be shared across repositories var records = GetShippingByTotalRecords(pageIndex, pageSize); totalCount = records.TotalCount; if (records.Count <= 0) { return(new List <ByTotalModel>()); } var allStores = _storeService.GetAllStores(); var result = records.Select(x => { var store = allStores.FirstOrDefault(y => y.Id == x.StoreId); var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId); var country = _countryService.GetCountryById(x.CountryId ?? 0); var stateProvince = _stateProvinceService.GetStateProvinceById(x.StateProvinceId ?? 0); var model = new ByTotalModel() { Id = x.Id, StoreId = x.StoreId, ShippingMethodId = x.ShippingMethodId, CountryId = x.CountryId, StateProvinceId = x.StateProvinceId, Zip = (x.Zip.HasValue() ? x.Zip : "*"), From = x.From, To = x.To, UsePercentage = x.UsePercentage, ShippingChargePercentage = x.ShippingChargePercentage, ShippingChargeAmount = x.ShippingChargeAmount, BaseCharge = x.BaseCharge, MaxCharge = x.MaxCharge, StoreName = (store == null ? "*" : store.Name), ShippingMethodName = (shippingMethod == null ? "".NaIfEmpty() : shippingMethod.Name), CountryName = (country == null ? "*" : country.Name), StateProvinceName = (stateProvince == null ? "*" : stateProvince.Name) }; return(model); }) .ToList(); return(result); }
public ActionResult RatesByCountryStateZipList(DataSourceRequest 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 CountryStateZipModel { 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 gridModel = new DataSourceResult { Data = taxRatesModel, Total = records.TotalCount }; return(Json(gridModel)); }
public string GetAddressline(Address model) { try { string addrLine = string.Empty; if (model != null) { addrLine += model.Address1 + ", "; addrLine += model.City + ", "; addrLine += _stateService.GetStateProvinceById(model.StateProvinceId.GetValueOrDefault()).Name + ", "; addrLine += _countryService.GetCountryById(model.CountryId.GetValueOrDefault()).Name + ", "; addrLine += model.ZipPostalCode; } return(addrLine); } catch { return(null); } }
public ActionResult TestRequest(ConfigurationModel model) { if (!ModelState.IsValid) { return(Configure()); } var country = _countryService.GetCountryById(model.TestAddress.CountryId); var sateProvince = _stateProvinceService.GetStateProvinceById(model.TestAddress.RegionId); var taxProvider = (ExactorTaxProvider)_taxService.LoadTaxProviderBySystemName("Tax.Exactor"); if (taxProvider == null) { ErrorNotification("Can't load tax provider"); return(Configure()); } var address = new Address { Country = country, StateProvince = sateProvince, City = model.TestAddress.City, Address1 = model.TestAddress.Address, ZipPostalCode = model.TestAddress.ZipPostalCode, FirstName = "nopCommerce", LastName = "Test" }; var taxResult = taxProvider.GetTaxRate(new CalculateTaxRequest { Address = address }); if (taxResult.Success) { SuccessNotification(String.Format(_localizationService.GetResource("Plugins.Tax.Exactor.TestSuccess"), taxResult.TaxRate)); } else { ErrorNotification(taxResult.Errors.Aggregate((all, curent) => all + "\r\n" + curent)); } return(Configure()); }
private void LoadingShipping(PostProcessPaymentRequest postProcessPaymentRequest, PaymentRequest payment) { payment.Shipping = new Shipping(); payment.Shipping.ShippingType = ShippingType.NotSpecified; Address adress = new Address(); adress.Complement = string.Empty; adress.District = string.Empty; adress.Number = string.Empty; if (postProcessPaymentRequest.Order.ShippingAddress != null) { adress.City = postProcessPaymentRequest.Order.ShippingAddress.City; adress.Country = _countryService.GetCountryById(postProcessPaymentRequest.Order.ShippingAddress.CountryId)?.Name; adress.PostalCode = postProcessPaymentRequest.Order.ShippingAddress.ZipPostalCode; adress.State = _stateProvinceService.GetStateProvinceById(postProcessPaymentRequest.Order.ShippingAddress.StateProvinceId)?.Name; adress.Street = postProcessPaymentRequest.Order.ShippingAddress.Address1; } payment.Shipping.Cost = Math.Round(GetConvertedRate(postProcessPaymentRequest.Order.OrderShippingInclTax), 2); }
private static ShippingOption GetDefaultShippingOption( IShippingService shippingService, IWorkContext workContext, IStoreContext storeContext, ICountryService countryService, IStateProvinceService stateProvinceService, IGenericAttributeService genericAttributeService) { // TODO: set these values in the config? - like EstimateShipping but default values are provided? int countryId = 80; // UK int? stateProvinceId = null; string zipPostalCode = "SB2 8BW"; Address address = new Address { CountryId = countryId, Country = countryService.GetCountryById(countryId), StateProvinceId = stateProvinceId, StateProvince = stateProvinceId.HasValue ? stateProvinceService.GetStateProvinceById(stateProvinceId.Value) : null, ZipPostalCode = zipPostalCode, }; if (workContext.CurrentCustomer.ShippingAddress != null) { address = workContext.CurrentCustomer.ShippingAddress; } List<ShoppingCartItem> cart = workContext.CurrentCustomer.ShoppingCartItems .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart) .LimitPerStore(storeContext.CurrentStore.Id) .ToList(); GetShippingOptionResponse shippingOptionResponse = shippingService.GetShippingOptions(cart, address); ShippingOption selectedShippingOption = shippingOptionResponse.ShippingOptions.FirstOrDefault(); genericAttributeService.SaveAttribute(workContext.CurrentCustomer, SystemCustomerAttributeNames.SelectedShippingOption, selectedShippingOption, storeContext.CurrentStore.Id); return selectedShippingOption; }