/// <summary> /// Prepare paged predefined product attribute value list model /// </summary> /// <param name="searchModel">Predefined product attribute value search model</param> /// <param name="productAttribute">Product attribute</param> /// <returns>Predefined product attribute value list model</returns> public virtual async Task <PredefinedProductAttributeValueListModel> PreparePredefinedProductAttributeValueListModelAsync( PredefinedProductAttributeValueSearchModel searchModel, ProductAttribute productAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (productAttribute == null) { throw new ArgumentNullException(nameof(productAttribute)); } //get predefined product attribute values var values = (await _productAttributeService.GetPredefinedProductAttributeValuesAsync(productAttribute.Id)).ToPagedList(searchModel); //prepare list model var model = new PredefinedProductAttributeValueListModel().PrepareToGrid(searchModel, values, () => { return(values.Select(value => { //fill in model values from the entity var predefinedProductAttributeValueModel = value.ToModel <PredefinedProductAttributeValueModel>(); //fill in additional values (not existing in the entity) predefinedProductAttributeValueModel.WeightAdjustmentStr = value.WeightAdjustment.ToString("G29"); predefinedProductAttributeValueModel.PriceAdjustmentStr = value.PriceAdjustment .ToString("G29") + (value.PriceAdjustmentUsePercentage ? " %" : string.Empty); return predefinedProductAttributeValueModel; })); }); return(model); }
public virtual IActionResult PredefinedProductAttributeValueList(PredefinedProductAttributeValueSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedKendoGridJson()); } //try to get a product attribute with the specified id var productAttribute = _productAttributeService.GetProductAttributeById(searchModel.ProductAttributeId) ?? throw new ArgumentException("No product attribute found with the specified id"); //prepare model var model = _productAttributeModelFactory.PreparePredefinedProductAttributeValueListModel(searchModel, productAttribute); return(Json(model)); }
/// <summary> /// Prepare paged predefined product attribute value list model /// </summary> /// <param name="searchModel">Predefined product attribute value search model</param> /// <param name="productAttribute">Product attribute</param> /// <returns>Predefined product attribute value list model</returns> public virtual PredefinedProductAttributeValueListModel PreparePredefinedProductAttributeValueListModel( PredefinedProductAttributeValueSearchModel searchModel, ProductAttribute productAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (productAttribute == null) { throw new ArgumentNullException(nameof(productAttribute)); } //get predefined product attribute values var values = _productAttributeService.GetPredefinedProductAttributeValues(productAttribute.Id); //prepare list model var model = new PredefinedProductAttributeValueListModel { Data = values.PaginationByRequestModel(searchModel).Select(value => { //fill in model values from the entity var predefinedProductAttributeValueModel = new PredefinedProductAttributeValueModel { Id = value.Id, ProductAttributeId = value.ProductAttributeId, Name = value.Name, IsPreSelected = value.IsPreSelected, DisplayOrder = value.DisplayOrder }; //fill in additional values (not existing in the entity) predefinedProductAttributeValueModel.WeightAdjustmentStr = value.WeightAdjustment.ToString("G29"); predefinedProductAttributeValueModel.PriceAdjustmentStr = value.PriceAdjustment .ToString("G29") + (value.PriceAdjustmentUsePercentage ? " %" : string.Empty); return(predefinedProductAttributeValueModel); }), Total = values.Count }; return(model); }
/// <summary> /// Prepare predefined product attribute value search model /// </summary> /// <param name="searchModel">Predefined product attribute value search model</param> /// <param name="productAttribute">Product attribute</param> /// <returns>Predefined product attribute value search model</returns> protected virtual PredefinedProductAttributeValueSearchModel PreparePredefinedProductAttributeValueSearchModel( PredefinedProductAttributeValueSearchModel searchModel, ProductAttribute productAttribute) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (productAttribute == null) { throw new ArgumentNullException(nameof(productAttribute)); } searchModel.ProductAttributeId = productAttribute.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <returns>A task that represents the asynchronous operation</returns> public virtual async Task <IActionResult> PredefinedProductAttributeValueList(PredefinedProductAttributeValueSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAttributes)) { return(await AccessDeniedDataTablesJson()); } //try to get a product attribute with the specified id var productAttribute = await _productAttributeService.GetProductAttributeByIdAsync(searchModel.ProductAttributeId) ?? throw new ArgumentException("No product attribute found with the specified id"); //prepare model var model = await _productAttributeModelFactory.PreparePredefinedProductAttributeValueListModelAsync(searchModel, productAttribute); return(Json(model)); }