/// <summary> /// Prepare paged state and province list model /// </summary> /// <param name="searchModel">State and province search model</param> /// <param name="country">Country</param> /// <returns>State and province list model</returns> public virtual StateProvinceListModel PrepareStateProvinceListModel(StateProvinceSearchModel searchModel, Country country) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (country == null) { throw new ArgumentNullException(nameof(country)); } //get comments var states = _stateProvinceService.GetStateProvincesByCountryId(country.Id, showHidden: true); //prepare list model var model = new StateProvinceListModel { //fill in model values from the entity Data = states.PaginationByRequestModel(searchModel).Select(state => state.ToModel <StateProvinceModel>()), Total = states.Count }; return(model); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> States(StateProvinceSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCountries)) { return(await AccessDeniedDataTablesJson()); } //try to get a country with the specified id var country = await _countryService.GetCountryByIdAsync(searchModel.CountryId) ?? throw new ArgumentException("No country found with the specified id"); //prepare model var model = await _countryModelFactory.PrepareStateProvinceListModelAsync(searchModel, country); return(Json(model)); }
public virtual IActionResult States(StateProvinceSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries)) { return(AccessDeniedKendoGridJson()); } //try to get a country with the specified id var country = _countryService.GetCountryById(searchModel.CountryId) ?? throw new ArgumentException("No country found with the specified id"); //prepare model var model = _countryModelFactory.PrepareStateProvinceListModel(searchModel, country); return(Json(model)); }
/// <summary> /// Prepare state and province search model /// </summary> /// <param name="searchModel">State and province search model</param> /// <param name="country">Country</param> /// <returns>State and province search model</returns> protected virtual StateProvinceSearchModel PrepareStateProvinceSearchModel(StateProvinceSearchModel searchModel, Country country) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (country == null) { throw new ArgumentNullException(nameof(country)); } searchModel.CountryId = country.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare paged state and province list model /// </summary> /// <param name="searchModel">State and province search model</param> /// <param name="country">Country</param> /// <returns>State and province list model</returns> public virtual StateProvinceListModel PrepareStateProvinceListModel(StateProvinceSearchModel searchModel, Country country) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (country == null) { throw new ArgumentNullException(nameof(country)); } //get comments var states = _stateProvinceService.GetStateProvincesByCountryId(country.Id, showHidden: true).ToPagedList(searchModel); //prepare list model var model = new StateProvinceListModel().PrepareToGrid(searchModel, states, () => { //fill in model values from the entity return(states.Select(state => state.ToModel <StateProvinceModel>())); }); return(model); }