/// <summary>
        /// Prepare paged country list model
        /// </summary>
        /// <param name="searchModel">Country search model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the country list model
        /// </returns>
        public virtual async Task <CountryListModel> PrepareCountryListModelAsync(CountrySearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get countries
            var countries = (await _countryService.GetAllCountriesAsync(showHidden: true)).ToPagedList(searchModel);

            //prepare list model
            var model = await new CountryListModel().PrepareToGridAsync(searchModel, countries, () =>
            {
                //fill in model values from the entity
                return(countries.SelectAwait(async country =>
                {
                    var countryModel = country.ToModel <CountryModel>();

                    countryModel.NumberOfStates = (await _stateProvinceService.GetStateProvincesByCountryIdAsync(country.Id))?.Count ?? 0;

                    return countryModel;
                }));
            });

            return(model);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepare paged country list model
        /// </summary>
        /// <param name="searchModel">Country search model</param>
        /// <returns>Country list model</returns>
        public virtual CountryListModel PrepareCountryListModel(CountrySearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get countries
            var countries = _countryService.GetAllCountries(showHidden: true).ToPagedList(searchModel);

            //prepare list model
            var model = new CountryListModel().PrepareToGrid(searchModel, countries, () =>
            {
                //fill in model values from the entity
                return(countries.Select(country =>
                {
                    var countryModel = country.ToModel <CountryModel>();
                    countryModel.NumberOfStates = country.StateProvinces?.Count ?? 0;

                    return countryModel;
                }));
            });

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepare paged country list model
        /// </summary>
        /// <param name="searchModel">Country search model</param>
        /// <returns>Country list model</returns>
        public virtual CountryListModel PrepareCountryListModel(CountrySearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get countries
            var countries = _countryService.GetAllCountries(showHidden: true);

            //prepare list model
            var model = new CountryListModel
            {
                //fill in model values from the entity
                Data = countries.PaginationByRequestModel(searchModel).Select(country =>
                {
                    var countryModel            = country.ToModel <CountryModel>();
                    countryModel.NumberOfStates = country.StateProvinces?.Count ?? 0;

                    return(countryModel);
                }),
                Total = countries.Count
            };

            return(model);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Search(CountrySearchModel countrySearchModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", new CountrySearchModel()));
            }

            var searchModel = await SearchCountry(countrySearchModel.Query);

            return(View("Index", searchModel));
        }
Exemplo n.º 5
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> CountryList(CountrySearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCountries))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = await _countryModelFactory.PrepareCountryListModelAsync(searchModel);

            return(Json(model));
        }
Exemplo n.º 6
0
        public virtual IActionResult CountryList(CountrySearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCountries))
            {
                return(AccessDeniedKendoGridJson());
            }

            //prepare model
            var model = _countryModelFactory.PrepareCountryListModel(searchModel);

            return(Json(model));
        }
Exemplo n.º 7
0
        public IActionResult CountriesList(CountrySearchModel searchModel)
        {
            var countries = _countryService.GetCountries(out int totalResults, searchModel.SearchPhrase, searchModel.Current,
                                                         searchModel.RowCount);

            var models = countries.Select(x => _modelMapper.Map <CountryModel>(x)).ToList();

            return(R.Success.WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .With("countries", models)
                   .WithParams(searchModel)
                   .Result);
        }
        /// <summary>
        /// Prepare country search model
        /// </summary>
        /// <param name="searchModel">Country search model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the country search model
        /// </returns>
        public virtual Task <CountrySearchModel> PrepareCountrySearchModelAsync(CountrySearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(Task.FromResult(searchModel));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Prepare country search model
        /// </summary>
        /// <param name="searchModel">Country search model</param>
        /// <returns>Country search model</returns>
        public virtual CountrySearchModel PrepareCountrySearchModel(CountrySearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Exemplo n.º 10
0
        private async Task <CountrySearchModel> SearchCountry(string countryCode)
        {
            Country searchResult = null;
            string  errorMsg     = null;

            try
            {
                searchResult = await _countryInfoService.GetCountryInfo(countryCode);
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
            }

            var model = new CountrySearchModel
            {
                Query        = countryCode,
                Result       = searchResult,
                ErrorMessage = errorMsg,
            };

            return(model);
        }