public async Task <ActionResult> Edit(int id) { ProductViewModel model = new ProductViewModel(); TEBApiResponse apiResponse = await Get("/Product/GetProductById?Id=" + id); if (apiResponse.IsSuccess) { Product product = JsonConvert.DeserializeObject <Product>(Convert.ToString(apiResponse.Data)); model = ProductMapping.ModelToView(product); } if (model != null) { TEBApiResponse apiResponses = await Get("/SpecificationAttribute/GetSpecificationAttributes"); if (apiResponses.IsSuccess) { List <SpecificationAttribute> list = JsonConvert.DeserializeObject <List <SpecificationAttribute> >(Convert.ToString(apiResponses.Data)); model.AddSpecificationAttributeModel.AvailableAttributes = list.Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); } } PrepareProductModel(model, null, false, false); //AddLocales(_languageService, model.Locales); //PrepareAclModel(model, null, false); //PrepareStoresMappingModel(model, null, false); //PrepareCategoryMappingModel(model, null, false); //PrepareManufacturerMappingModel(model, null, false); //PrepareDiscountMappingModel(model, null, false); return(View(model)); }
public async Task <ActionResult> ProductList(DataSourceRequest command, ProductSearchViewModel model) { var categoryIds = model.SearchCategoryId > 0 ? new List <int> { model.SearchCategoryId } : null; ////include subcategories //if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0) // categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId)); bool?overridePublished = null; if (model.SearchPublishedId == 1) { overridePublished = true; } else if (model.SearchPublishedId == 2) { overridePublished = false; } SearchProductModel searchmodel = new SearchProductModel { categoryIds = categoryIds, manufacturerId = model.SearchManufacturerId, storeId = model.SearchStoreId, vendorId = model.SearchVendorId, warehouseId = model.SearchWarehouseId, productType = model.SearchProductTypeId > 0 ? (ProductType?)model.SearchProductTypeId : null, keywords = model.SearchProductName, pageIndex = command.Page - 1, pageSize = command.PageSize, showHidden = true, overridePublished = overridePublished }; TEBApiResponse apiResponse = await Post <SearchProductModel>("/Product/SearchProducts", searchmodel); if (apiResponse.IsSuccess) { try { List <Product> listproducts = JsonConvert.DeserializeObject <List <Product> >(Convert.ToString(apiResponse.Data)); PagedList <Product> products = new PagedList <Product>(listproducts, 0, 10); var gridModel = new DataSourceResult(); gridModel.Data = products.Select(x => { var productModel = ProductMapping.ModelToView(x); // x.ToModel(); //little performance optimization: ensure that "FullDescription" is not returned productModel.FullDescription = ""; ////picture //var defaultProductPicture = _pictureService.GetPicturesByProductId(x.Id, 1).FirstOrDefault(); //productModel.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true); ////product type //productModel.ProductTypeName = x.ProductType.GetLocalizedEnum(_localizationService, _workContext); ////friendly stock qantity ////if a simple product AND "manage inventory" is "Track inventory", then display //if (x.ProductType == ProductType.SimpleProduct && x.ManageInventoryMethod == ManageInventoryMethod.ManageStock) // productModel.StockQuantityStr = x.GetTotalStockQuantity().ToString(); return(productModel); }); gridModel.Total = products.TotalCount; return(Json(gridModel)); } catch (Exception ex) { throw; } } return(Json(0)); }