public virtual async Task <CustomerGroupProductModel.AddProductModel> PrepareProductModel(string customerGroupId) { var model = new CustomerGroupProductModel.AddProductModel(); model.CustomerGroupId = customerGroupId; //stores model.AvailableStores.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " }); foreach (var s in await _storeService.GetAllStores()) { model.AvailableStores.Add(new SelectListItem { Text = s.Shortcut, Value = s.Id.ToString() }); } //vendors model.AvailableVendors.Add(new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " }); foreach (var v in await _vendorService.GetAllVendors(showHidden: true)) { model.AvailableVendors.Add(new SelectListItem { Text = v.Name, Value = v.Id.ToString() }); } //product types model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList().ToList(); model.AvailableProductTypes.Insert(0, new SelectListItem { Text = _translationService.GetResource("Admin.Common.All"), Value = " " }); return(model); }
public async Task <IActionResult> ProductAddPopup(CustomerGroupProductModel.AddProductModel model) { if (model.SelectedProductIds != null) { await _customerGroupViewModelService.InsertProductModel(model); } //a vendor should have access only to his products ViewBag.RefreshPage = true; return(View(model)); }
public virtual async Task InsertProductModel(CustomerGroupProductModel.AddProductModel model) { foreach (string id in model.SelectedProductIds) { var product = await _productService.GetProductById(id); if (product != null) { var customerGroupProduct = await _customerGroupProductService.GetCustomerGroupProduct(model.CustomerGroupId, id); if (customerGroupProduct == null) { customerGroupProduct = new CustomerGroupProduct(); customerGroupProduct.CustomerGroupId = model.CustomerGroupId; customerGroupProduct.ProductId = id; customerGroupProduct.DisplayOrder = 0; await _customerGroupProductService.InsertCustomerGroupProduct(customerGroupProduct); } } } }
public async Task <IActionResult> ProductAddPopupList(DataSourceRequest command, CustomerGroupProductModel.AddProductModel model) { var products = await _customerGroupViewModelService.PrepareProductModel(model, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = products.products, Total = products.totalCount }; return(Json(gridModel)); }
public virtual async Task <(IList <ProductModel> products, int totalCount)> PrepareProductModel(CustomerGroupProductModel.AddProductModel model, int pageIndex, int pageSize) { var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchBrandId, model.SearchCollectionId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId, model.SearchProductName, pageIndex, pageSize); return(products.Select(x => x.ToModel(_dateTimeService)).ToList(), products.TotalCount); }