public virtual IActionResult AssociateProductToCustomerRolePopupList(CustomerRoleProductSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers)) { return(AccessDeniedKendoGridJson()); } //prepare model var model = _customerRoleModelFactory.PrepareCustomerRoleProductListModel(searchModel); return(Json(model)); }
/// <summary> /// Prepare paged customer role product list model /// </summary> /// <param name="searchModel">Customer role product search model</param> /// <returns>Customer role product list model</returns> public virtual CustomerRoleProductListModel PrepareCustomerRoleProductListModel(CustomerRoleProductSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { searchModel.SearchVendorId = _workContext.CurrentVendor.Id; } //get products var products = _productService.SearchProducts(showHidden: true, categoryIds: new List <int> { searchModel.SearchCategoryId }, manufacturerId: searchModel.SearchManufacturerId, storeId: searchModel.SearchStoreId, vendorId: searchModel.SearchVendorId, productType: searchModel.SearchProductTypeId > 0 ? (ProductType?)searchModel.SearchProductTypeId : null, keywords: searchModel.SearchProductName, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare grid model var model = new CustomerRoleProductListModel { //fill in model values from the entity Data = products.Select(product => product.ToModel <ProductModel>()), Total = products.TotalCount }; return(model); }
/// <summary> /// Prepare customer role product search model /// </summary> /// <param name="searchModel">Customer role product search model</param> /// <returns>Customer role product search model</returns> public virtual CustomerRoleProductSearchModel PrepareCustomerRoleProductSearchModel(CustomerRoleProductSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //a vendor should have access only to his products searchModel.IsLoggedInAsVendor = _workContext.CurrentVendor != null; //prepare available categories _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories); //prepare available manufacturers _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers); //prepare available stores _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores); //prepare available vendors _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors); //prepare available product types _baseAdminModelFactory.PrepareProductTypes(searchModel.AvailableProductTypes); //prepare page parameters searchModel.SetPopupGridPageSize(); return(searchModel); }
/// <summary> /// Prepare paged customer role product list model /// </summary> /// <param name="searchModel">Customer role product search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the customer role product list model /// </returns> public virtual async Task <CustomerRoleProductListModel> PrepareCustomerRoleProductListModelAsync(CustomerRoleProductSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //a vendor should have access only to his products var currentVendor = await _workContext.GetCurrentVendorAsync(); if (currentVendor != null) { searchModel.SearchVendorId = currentVendor.Id; } //get products var products = await _productService.SearchProductsAsync(showHidden : true, categoryIds : new List <int> { searchModel.SearchCategoryId }, manufacturerIds : new List <int> { searchModel.SearchManufacturerId }, storeId : searchModel.SearchStoreId, vendorId : searchModel.SearchVendorId, productType : searchModel.SearchProductTypeId > 0?(ProductType?)searchModel.SearchProductTypeId : null, keywords : searchModel.SearchProductName, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize); //prepare grid model var model = await new CustomerRoleProductListModel().PrepareToGridAsync(searchModel, products, () => { return(products.SelectAwait(async product => { var productModel = product.ToModel <ProductModel>(); productModel.SeName = await _urlRecordService.GetSeNameAsync(product, 0, true, false); return productModel; })); }); return(model); }
public virtual async Task <IActionResult> AssociateProductToCustomerRolePopupList(CustomerRoleProductSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageCustomers) || !await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageAcl)) { return(await AccessDeniedDataTablesJson()); } //prepare model var model = await _customerRoleModelFactory.PrepareCustomerRoleProductListModelAsync(searchModel); return(Json(model)); }