public virtual IActionResult ValueList(AddressAttributeValueSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedKendoGridJson());
            }

            //try to get an address attribute with the specified id
            var addressAttribute = _addressAttributeService.GetAddressAttributeById(searchModel.AddressAttributeId)
                                   ?? throw new ArgumentException("No address attribute found with the specified id");

            //prepare model
            var model = _addressAttributeModelFactory.PrepareAddressAttributeValueListModel(searchModel, addressAttribute);

            return(Json(model));
        }
        public virtual async Task <IActionResult> ValueList(AddressAttributeValueSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSettings))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get an address attribute with the specified id
            var addressAttribute = await _addressAttributeService.GetAddressAttributeByIdAsync(searchModel.AddressAttributeId)
                                   ?? throw new ArgumentException("No address attribute found with the specified id");

            //prepare model
            var model = await _addressAttributeModelFactory.PrepareAddressAttributeValueListModelAsync(searchModel, addressAttribute);

            return(Json(model));
        }
        /// <summary>
        /// Prepare address attribute value search model
        /// </summary>
        /// <param name="searchModel">Address attribute value search model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <returns>Address attribute value search model</returns>
        protected virtual AddressAttributeValueSearchModel PrepareAddressAttributeValueSearchModel(AddressAttributeValueSearchModel searchModel, AddressAttribute addressAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (addressAttribute == null)
            {
                throw new ArgumentNullException(nameof(addressAttribute));
            }

            searchModel.AddressAttributeId = addressAttribute.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare paged address attribute value list model
        /// </summary>
        /// <param name="searchModel">Address attribute value search model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the address attribute value list model
        /// </returns>
        public virtual async Task <AddressAttributeValueListModel> PrepareAddressAttributeValueListModelAsync(AddressAttributeValueSearchModel searchModel,
                                                                                                              AddressAttribute addressAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (addressAttribute == null)
            {
                throw new ArgumentNullException(nameof(addressAttribute));
            }

            //get address attribute values
            var addressAttributeValues = (await _addressAttributeService.GetAddressAttributeValuesAsync(addressAttribute.Id)).ToPagedList(searchModel);

            //prepare grid model
            var model = new AddressAttributeValueListModel().PrepareToGrid(searchModel, addressAttributeValues, () =>
            {
                //fill in model values from the entity
                return(addressAttributeValues.Select(value => value.ToModel <AddressAttributeValueModel>()));
            });

            return(model);
        }
        /// <summary>
        /// Prepare paged address attribute value list model
        /// </summary>
        /// <param name="searchModel">Address attribute value search model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <returns>Address attribute value list model</returns>
        public virtual AddressAttributeValueListModel PrepareAddressAttributeValueListModel(AddressAttributeValueSearchModel searchModel,
            AddressAttribute addressAttribute)
        {
            if (searchModel == null)
                throw new ArgumentNullException(nameof(searchModel));

            if (addressAttribute == null)
                throw new ArgumentNullException(nameof(addressAttribute));

            //get address attribute values
            var addressAttributeValues = _addressAttributeService.GetAddressAttributeValues(addressAttribute.Id);

            //prepare grid model
            var model = new AddressAttributeValueListModel
            {
                //fill in model values from the entity
                Data = addressAttributeValues.PaginationByRequestModel(searchModel).Select(value => value.ToModel<AddressAttributeValueModel>()),
                Total = addressAttributeValues.Count
            };

            return model;
        }
        /// <summary>
        /// Prepare paged address attribute value list model
        /// </summary>
        /// <param name="searchModel">Address attribute value search model</param>
        /// <param name="addressAttribute">Address attribute</param>
        /// <returns>Address attribute value list model</returns>
        public virtual AddressAttributeValueListModel PrepareAddressAttributeValueListModel(AddressAttributeValueSearchModel searchModel,
                                                                                            AddressAttribute addressAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (addressAttribute == null)
            {
                throw new ArgumentNullException(nameof(addressAttribute));
            }

            //get address attribute values
            var addressAttributeValues = _addressAttributeService.GetAddressAttributeValues(addressAttribute.Id);

            //prepare grid model
            var model = new AddressAttributeValueListModel
            {
                //fill in model values from the entity
                Data = addressAttributeValues.PaginationByRequestModel(searchModel).Select(value => new AddressAttributeValueModel
                {
                    Id = value.Id,
                    AddressAttributeId = value.AddressAttributeId,
                    Name          = value.Name,
                    IsPreSelected = value.IsPreSelected,
                    DisplayOrder  = value.DisplayOrder
                }),
                Total = addressAttributeValues.Count
            };

            return(model);
        }