Beispiel #1
0
        public virtual IActionResult ValueList(VendorAttributeValueSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
                return AccessDeniedKendoGridJson();

            //try to get a vendor attribute with the specified id
            var vendorAttribute = _vendorAttributeService.GetVendorAttributeById(searchModel.VendorAttributeId)
                ?? throw new ArgumentException("No vendor attribute found with the specified id");

            //prepare model
            var model = _vendorAttributeModelFactory.PrepareVendorAttributeValueListModel(searchModel, vendorAttribute);

            return Json(model);
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> ValueList(VendorAttributeValueSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSettings))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get a vendor attribute with the specified id
            var vendorAttribute = await _vendorAttributeService.GetVendorAttributeByIdAsync(searchModel.VendorAttributeId)
                                  ?? throw new ArgumentException("No vendor attribute found with the specified id");

            //prepare model
            var model = await _vendorAttributeModelFactory.PrepareVendorAttributeValueListModelAsync(searchModel, vendorAttribute);

            return(Json(model));
        }
        /// <summary>
        /// Prepare vendor attribute value search model
        /// </summary>
        /// <param name="searchModel">Vendor attribute value search model</param>
        /// <param name="vendorAttribute">Vendor attribute</param>
        /// <returns>Vendor attribute value search model</returns>
        protected virtual VendorAttributeValueSearchModel PrepareVendorAttributeValueSearchModel(VendorAttributeValueSearchModel searchModel,
                                                                                                 VendorAttribute vendorAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            searchModel.VendorAttributeId = vendorAttribute.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare paged vendor attribute value list model
        /// </summary>
        /// <param name="searchModel">Vendor attribute value search model</param>
        /// <param name="vendorAttribute">Vendor attribute</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the vendor attribute value list model
        /// </returns>
        public virtual async Task <VendorAttributeValueListModel> PrepareVendorAttributeValueListModelAsync(VendorAttributeValueSearchModel searchModel,
                                                                                                            VendorAttribute vendorAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get vendor attribute values
            var vendorAttributeValues = (await _vendorAttributeService.GetVendorAttributeValuesAsync(vendorAttribute.Id)).ToPagedList(searchModel);

            //prepare list model
            var model = new VendorAttributeValueListModel().PrepareToGrid(searchModel, vendorAttributeValues, () =>
            {
                //fill in model values from the entity
                return(vendorAttributeValues.Select(value => value.ToModel <VendorAttributeValueModel>()));
            });

            return(model);
        }
        /// <summary>
        /// Prepare paged vendor attribute value list model
        /// </summary>
        /// <param name="searchModel">Vendor attribute value search model</param>
        /// <param name="vendorAttribute">Vendor attribute</param>
        /// <returns>Vendor attribute value list model</returns>
        public virtual VendorAttributeValueListModel PrepareVendorAttributeValueListModel(VendorAttributeValueSearchModel searchModel,
                                                                                          VendorAttribute vendorAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get vendor attribute values
            var vendorAttributeValues = _vendorAttributeService.GetVendorAttributeValues(vendorAttribute.Id);

            //prepare list model
            var model = new VendorAttributeValueListModel
            {
                //fill in model values from the entity
                Data  = vendorAttributeValues.PaginationByRequestModel(searchModel).Select(value => value.ToModel <VendorAttributeValueModel>()),
                Total = vendorAttributeValues.Count
            };

            return(model);
        }