示例#1
0
        public virtual ActionResult List()
        {
            ProductListModel productListModel = new ProductListModel();

            PrepareProductListModel(productListModel);
            return(View(productListModel));
        }
示例#2
0
        public IActionResult Index()
        {
            var model = new ProductListModel();

            model.Products = _productService.GetAll();
            return(View(model));
        }
示例#3
0
        /// <summary>
        /// 下架商品列表
        /// </summary>
        /// <param name="storeName">店铺名称</param>
        /// <param name="productName">商品名称</param>
        /// <param name="categoryName">分类名称</param>
        /// <param name="brandName">品牌名称</param>
        /// <param name="storeId">店铺id</param>
        /// <param name="cateId">分类id</param>
        /// <param name="brandId">品牌id</param>
        /// <param name="pageNumber">当前页数</param>
        /// <param name="pageSize">每页数</param>
        /// <returns></returns>
        public ActionResult OutSaleProductList(string storeName, string productName, string categoryName, string brandName, string sortColumn, string sortDirection, int storeId = -1, int cateId = -1, int brandId = -1, int pageNumber = 1, int pageSize = 15)
        {
            string condition = AdminProducts.AdminGetProductListCondition(storeId, 0, productName, cateId, brandId, (int)ProductState.OutSale);
            string sort      = AdminProducts.AdminGetProductListSort(sortColumn, sortDirection);

            PageModel pageModel = new PageModel(pageSize, pageNumber, AdminProducts.AdminGetProductCount(condition));

            ProductListModel model = new ProductListModel()
            {
                ProductList   = AdminProducts.AdminGetProductList(pageModel.PageSize, pageModel.PageNumber, condition, sort),
                PageModel     = pageModel,
                SortColumn    = sortColumn,
                SortDirection = sortDirection,
                StoreId       = storeId,
                ProductName   = productName,
                CateId        = cateId,
                BrandId       = brandId,
                StoreName     = string.IsNullOrWhiteSpace(storeName) ? "全部店铺" : storeName,
                CategoryName  = string.IsNullOrWhiteSpace(categoryName) ? "全部分类" : categoryName,
                BrandName     = string.IsNullOrWhiteSpace(brandName) ? "全部品牌" : brandName
            };

            MallUtils.SetAdminRefererCookie(string.Format("{0}?pageNumber={1}&pageSize={2}&sortColumn={3}&sortDirection={4}&storeId={5}&ProductName={6}&cateId={7}&brandId={8}&storeName={9}&categoryName={10}&brandName={11}",
                                                          Url.Action("outsaleproductlist"),
                                                          pageModel.PageNumber, pageModel.PageSize,
                                                          sortColumn, sortDirection,
                                                          storeId, productName, cateId, brandId,
                                                          storeName, categoryName, brandName));
            return(View(model));
        }
示例#4
0
        /// <summary>
        /// 下架商品列表
        /// </summary>
        /// <param name="productName">商品名称</param>
        /// <param name="categoryName">分类名称</param>
        /// <param name="brandName">品牌名称</param>
        /// <param name="cateId">分类id</param>
        /// <param name="brandId">品牌id</param>
        /// <param name="pageNumber">当前页数</param>
        /// <param name="pageSize">每页数</param>
        /// <returns></returns>
        public ActionResult OutSaleProductList(string productName, string categoryName, string brandName, int cateId = -1, int brandId = -1, int pageNumber = 1, int pageSize = 15)
        {
            string condition = AdminProducts.AdminGetProductListCondition(productName, cateId, brandId, (int)ProductState.OutSale);

            PageModel pageModel = new PageModel(pageSize, pageNumber, AdminProducts.AdminGetProductCount(condition));

            ProductListModel model = new ProductListModel()
            {
                PageModel    = pageModel,
                ProductList  = AdminProducts.AdminGetProductList(pageModel.PageSize, pageModel.PageNumber, condition),
                CateId       = cateId,
                CategoryName = string.IsNullOrWhiteSpace(categoryName) ? "全部分类" : categoryName,
                BrandId      = brandId,
                BrandName    = string.IsNullOrWhiteSpace(brandName) ? "全部品牌" : brandName,
                ProductName  = productName
            };

            ShopUtils.SetAdminRefererCookie(string.Format("{0}?pageNumber={1}&pageSize={2}&ProductName={3}&cateId={4}&brandId={5}&categoryName={6}&brandName={7}",
                                                          Url.Action("outsaleproductlist"),
                                                          pageModel.PageNumber, pageModel.PageSize,
                                                          productName,
                                                          cateId, brandId,
                                                          categoryName, brandName));
            return(View(model));
        }
示例#5
0
        // List products in the store
        public ActionResult List()
        {
            if (!permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedView());
            }
            var model = new ProductListModel();

            //categories
            model.AvailableCategories.Add(
                new SelectListItem
            {
                Text  = "All",
                Value = "0"
            });
            var categories = categoryService.GetAllCategories();

            foreach (var c in categories)
            {
                model.AvailableCategories.Add(
                    new SelectListItem
                {
                    Text  = c.Name,
                    Value = c.Id.ToString()
                });
            }

            return(View(model));
        }
示例#6
0
        public ProductListModel FindProductsListModel(int brandId,
                                                      int availabilityId,
                                                      int index           = 0,
                                                      int pageNo          = 1,
                                                      int pageSize        = Int32.MaxValue,
                                                      string search       = "",
                                                      string sortColumn   = "",
                                                      SortOrder sortOrder = SortOrder.Asc)
        {
            var model = new ProductListModel();

            string mediaUrl = MediaServices.GetProductImageFolder(true);

            // Do a case-insensitive search
            model.GridIndex = index;
            var allItems = db.FindProductsForBrand(brandId, sortColumn, sortOrder, true)
                           .Where(p => (availabilityId == 0 || p.ProductAvailabilityId == availabilityId) &&
                                  (string.IsNullOrEmpty(search) ||
                                   (p.ItemName != null && p.ItemName.ToLower().Contains(search.ToLower())) ||
                                   (p.ItemNumber != null && p.ItemNumber.ToLower().Contains(search.ToLower()))));

            model.TotalRecords = allItems.Count();

            if (sortColumn.ToLower() == "productstatustext")
            {
                // Sorting done here because the text is not obtained from database field
                foreach (var item in allItems)
                {
                    var newItem = MapToModel(item);
                    newItem.Picture = (item.ProductMedia != null ? item.ProductMedia.Medium.FolderName + item.ProductMedia.Medium.FileName : "");
                    model.Items.Add(newItem);
                }

                if (sortOrder == SortOrder.Desc)
                {
                    model.Items = model.Items
                                  .OrderByDescending(i => i.ProductStatusText)
                                  .Skip((pageNo - 1) * pageSize)
                                  .Take(pageSize)
                                  .ToList();
                }
                else
                {
                    model.Items = model.Items
                                  .OrderBy(i => i.ProductStatusText)
                                  .Skip((pageNo - 1) * pageSize)
                                  .Take(pageSize)
                                  .ToList();
                }
            }
            else
            {
                foreach (var item in allItems.Skip((pageNo - 1) * pageSize)
                         .Take(pageSize))
                {
                    model.Items.Add(MapToModel(item));
                }
            }
            return(model);
        }
        public ActionResult Index()
        {
            var products = ProductService.GetProducts();
            var model    = new ProductListModel(products);

            return(View(model));
        }
        public async Task <IActionResult> Get([FromRoute] int Id, [FromRoute] int id)
        {
            var stockUnit = await _stockUnitsRepository.GetAsync(Id);

            if (stockUnit == null)
            {
                return(NotFound());
            }

            var products = await _productRepository.Query().Where(p => p.Id == Id).Take(20).ToListAsync();

            if (products == null)
            {
                return(NotFound());
            }

            var result = new ProductListModel
            {
                Products = products.Select(p => new ProductModel
                {
                    ProductId   = p.Id,
                    Name        = p.Name,
                    Description = p.Description,
                    Price       = p.Price,
                    Size        = p.Size
                })
            };

            return(Ok(result));
        }
示例#9
0
        public ActionResult Index()
        {
            ProductListModel     productsListModel    = _getProductsQuery.Execute(new ProductCriteriaModel());
            ProductListViewModel productListViewModel = _mapper.Map <ProductListViewModel>(productsListModel);

            return(View("Products", productListViewModel));
        }
示例#10
0
        public IActionResult each_user_ProductList([FromBody] ProductListModel model)
        {
            TranStatus transaction = new TranStatus();
            Dictionary <String, Object> dctData = new Dictionary <string, object>();
            HttpStatusCode statusCode           = HttpStatusCode.OK;

            try
            {
                List <ProductListModel> each_user_ProductList = new List <ProductListModel>();
                int rowcount = 0;
                each_user_ProductList = iproduct.each_user_ProductList(model, out rowcount);
                dctData.Add("each_user_ProductList", each_user_ProductList);
                dctData.Add("RowCount", rowcount);

                //var clientList = await iclient.each_admin_ClientList(model);
                //dctData.Add("each_admin_ClientList", clientList);
            }
            catch (Exception ex)
            {
                transaction = CommonHelper.TransactionErrorHandler(ex);
                statusCode  = HttpStatusCode.BadRequest;
            }
            dctData.Add("Status", transaction);
            return(this.StatusCode(Convert.ToInt32(statusCode), dctData));
        }
示例#11
0
        public async Task <IActionResult> updateProduct(int ID, [FromBody] ProductListModel model)
        {
            Dictionary <String, Object> dctData = new Dictionary <string, object>();
            HttpStatusCode statusCode           = HttpStatusCode.OK;
            TranStatus     transaction          = new TranStatus();

            //try
            //{
            //    model.Image = CommonHelper.SaveImage(HttpContext, "Images\\Product", model.Image, true, model.ImageExtn);
            //    transaction = await iproduct.updateProduct(ID, model);

            //}

            try
            {
                //This for loop for adding the multiple Image


                for (var i = 0; i < model.ImageList.Count; i++)
                {
                    model.ImageListData[i].Image = CommonHelper.SaveImage(HttpContext, "Images\\Product", model.ImageList[i].ImageData, true, model.ImageList[i].ImageExtn);
                }
                transaction = await iproduct.updateProduct(ID, model);
            }
            catch (Exception ex)
            {
                transaction = CommonHelper.TransactionErrorHandler(ex);
                statusCode  = HttpStatusCode.BadRequest;
            }
            dctData.Add("Status", transaction);
            return(this.StatusCode(Convert.ToInt32(statusCode), dctData));
        }
示例#12
0
        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <param name="cid">类目ID</param>
        /// <param name="level">类目级别</param>
        /// <param name="sort">排序方式</param>
        /// <param name="pageindex">第几页</param>
        /// <param name="pagesize">每页显示多少条数据</param>
        /// <returns></returns>
        public ActionResult GetProductList(string cid, int level, int sort, int pageindex, int pagesize)
        {
            ProductListModel         viewmodel     = new ProductListModel();
            List <CategoryAttribute> attributeList = new List <CategoryAttribute>();

            try
            {
                int      totalRecords = 0;
                string[] c            = new string[] { cid };
                viewmodel.Products    = productBll.GetProductListNew(c, level, new List <int>(), sort, pageindex, pagesize, base.language, base.DeliveryRegion, base.ExchangeRate, ref attributeList, out totalRecords);
                viewmodel.TotalRecord = totalRecords;
                List <string> spus    = viewmodel.Products.Select(x => x.SPU).ToList();
                var           spuSkus = productBll.GetSkuBySpu(spus).Select();
                if (viewmodel.Products != null && viewmodel.Products.Count > 0)
                {
                    foreach (var p in viewmodel.Products)
                    {
                        p.MinPrice      = (p.MinPrice * ExchangeRate).ToNumberRound(2);
                        p.DiscountPrice = (p.DiscountPrice * ExchangeRate).ToNumberRound(2);
                        p.DiscountRate  = Convert.ToDecimal(p.DiscountRate).ToNumberStringFloat();
                        p.Sku           = Convert.ToString(spuSkus.Where(x => Convert.ToString(x["Spu"]) == p.SPU).FirstOrDefault()["sku"]);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(this.PartialView("ProductList", viewmodel));
        }
 public List <ProductListModel> each_user_ProductList(ProductListModel model, out int RowCount)
 {
     using (productRepository = new ProductRepository())
     {
         return(productRepository.each_user_ProductList(model, out RowCount));
     }
 }
 //Update
 public async Task <TranStatus> updateProduct(int ID, ProductListModel model)
 {
     using (productRepository = new ProductRepository())
     {
         return(await productRepository.updateProduct(ID, model));
     }
 }
示例#15
0
        public dynamic RetrieveProducts()
        {
            var products         = _productsDao.FindAll();
            var productListModel = new ProductListModel(products, _hostName);

            return(productListModel);
        }
示例#16
0
        public List <ProductListModel> GetAllProductsList()
        {
            var model = new List <ProductListModel>();

            var tmpAllProducts = _unitOfWork.productRepository.GetAll().Where(p => p.Deleted.Equals(false)).ToList();

            foreach (var tmpProduct in tmpAllProducts)
            {
                ProductListModel singleProductListModel = new ProductListModel();

                //--below loop copy product value from retrieved list
                foreach (var propDest in singleProductListModel.GetType().GetProperties())
                {
                    //Find property in source based on destination name
                    var propSrc = tmpProduct.GetType().GetProperty(propDest.Name);
                    if (propSrc != null)
                    {
                        //Get value from source and assign it to destination
                        propDest.SetValue(singleProductListModel, propSrc.GetValue(tmpProduct));
                    }
                }

                model.Add(singleProductListModel);
            }

            return(model);
        }
        //Update
        public async Task <TranStatus> updateProduct(int ID, ProductListModel model)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                await connection.OpenAsync();

                TranStatus        transaction = new TranStatus();
                DynamicParameters parameter   = new DynamicParameters();
                parameter.Add("@Product_ID", ID);
                parameter.Add("@Cid", model.Cid);
                parameter.Add("@Sid", model.Sid);
                parameter.Add("@Productname", model.Productname);
                parameter.Add("@Description", model.Description);
                parameter.Add("@Price", model.Price);
                //parameter.Add("@Image", model.Image);
                //parameter.Add("@Date", model.Date);
                parameter.Add("@Modifiedby", model.Modifiedby);
                //Data Table Type -- to update multiple image
                DataTable dataTable = CommonHelper.ToDataTable(model.ImageListData);
                parameter.Add("@ImageListing", dataTable.AsTableValuedParameter("dbo.ImageList"));
                parameter.Add("@Message", dbType: DbType.String, direction: ParameterDirection.Output, size: 500);
                parameter.Add("@Code", dbType: DbType.Int32, direction: ParameterDirection.Output);
                await connection.QueryAsync("updateProduct", parameter, commandType : CommandType.StoredProcedure);

                transaction.returnMessage = parameter.Get <string>("@Message");
                transaction.code          = parameter.Get <int>("@Code");
                return(transaction);
            }
        }
示例#18
0
        public IActionResult GetHistory()
        {
            var userId = Int32.Parse(_userManager.GetUserId(User));
            var histId = _products.GetHistoryByUserId(userId);
            var hist   = _products.GetByHistoryId(histId);


            var historyModel = hist.Select(a => new ProductModel
            {
                ItemId = a.Id,
                ManufacturerAndModel = _products.GetProductName(a.Id),
                Model            = _products.GetModelName(a.Id),
                FirstImage       = _products.GetFirstImage(a.Id),
                Price            = a.Price,
                AvrageUserRating = _products.GetAvrageRating(a.Id),
                Discount         = a.Discount
            });

            var send = new ProductListModel
            {
                ProductHistory = historyModel
            };

            return(PartialView("History", send));
        }
        // GET: Products
        public ActionResult Index(ProductListModel productSearchModel)
        {
            ViewBag.CategoryID    = new SelectList(db.Categories, "CategoryID", "CategoryName");
            ViewBag.SubCategoryID = new SelectList(db.SubCategories, "SubCategoryID", "Name");
            ViewBag.SupplierID    = new SelectList(db.Suppliers, "SupplierID", "CompanyName");
            var ProductList = db.Products.Include(p => p.Category).Include(p => p.SubCategory).Include(p => p.Supplier);

            if (!string.IsNullOrEmpty(productSearchModel.SearchButton))
            {
                if (productSearchModel.CategoryID > 0)
                {
                    ProductList = ProductList.Where(p => p.CategoryID == productSearchModel.CategoryID);
                }

                if (productSearchModel.SubCategoryID > 0)
                {
                    ProductList = ProductList.Where(p => p.SubCategoryID == productSearchModel.SubCategoryID);
                }

                if (productSearchModel.SupplierID > 0)
                {
                    ProductList = ProductList.Where(p => p.SupplierID == productSearchModel.SupplierID);
                }
            }

            productSearchModel.Products = ProductList.ToList();



            return(View(productSearchModel));
        }
示例#20
0
        public JsonResult RefreshItems([FromBody] ProductListModel modl)
        {
            var product = _products.GetItemsRefreshFilter(/*modl.ProductId,*/ modl.Name, modl.ManufacturerList, modl.SubCategories);

            var model = product.Select(a => new ProductIndexModel
            {
                ItemId           = a.Id,
                ManufacturerName = _products.GetManufacturerNameString(a.Id),
                ModelName        = _products.GetModelNameString(a.Id),
                FirstImage       = _products.GetFirstImage(a.Id),
                Price            = a.Price,
                Discount         = a.Discount,
                AvrageUserRating = _products.GetAvrageRating(a.Id),
                ItemSubType      = _products.GetSubCategory(a.Id)
            });

            var priceFilter = FilterByPrice(model, modl.MinPrice, modl.MaxPrice);
            var sort        = Sort(priceFilter.ProductIndex, modl.Sort);

            var send = new ProductListModel {
                ProductIndex = sort.ProductIndex,
            };

            return(Json(send));
        }
示例#21
0
        public ActionResult StockInfo(DataSourceRequest command, ProductListModel model)
        {
            if (!permissionService.Authorize(StandardPermissionProvider.InventoryProduct))
            {
                return(AccessDeniedView());
            }
            if (ModelState.IsValid)
            {
                var psm = inventoryService.GetProductInventories(model.SearchProductName,
                                                                 model.SearchCategoryId, model.SearchStoreId);


                var gridModel = new DataSourceResult
                {
                    Data = psm.Select(
                        x => new
                    {
                        ProductName = x.Product.Name,
                        StoreName   = x.Store.Name,
                        Quantity    = x.Quantity
                    }),
                    Total = psm.Count
                };

                return(Json(gridModel));
            }
            return(Json(false));
        }
示例#22
0
        public IActionResult Index(string _name, string _itemGroup)
        {
            try
            {
                var product = _products.GetByType(_name);

                var model = product.Select(a => new ProductIndexModel
                {
                    ItemId           = a.Id,
                    ManufacturerName = _products.GetManufacturerNameString(a.Id),
                    Price            = a.Price,
                    ItemSubType      = _products.GetSubCategory(a.Id)
                });

                var uniqueManList  = new HashSet <string>();
                var uniquePrices   = new HashSet <double>();
                var uniqueSubTypes = new HashSet <string>();

                foreach (var mod in model)
                {
                    uniqueManList.Add(mod.ManufacturerName);
                    uniquePrices.Add(mod.Price);
                    uniqueSubTypes.Add(mod.ItemSubType);
                }

                var productmodel = new ProductListModel
                {
                    ProductIndex     = model,
                    ItemGroup        = _itemGroup,
                    Name             = _name,
                    ManufacturerList = uniqueManList,
                    NumberOfItems    = model.Count().ToString(),
                    MinPrice         = uniquePrices.Min(),
                    MaxPrice         = uniquePrices.Max(),
                    SubCategories    = uniqueSubTypes,
                    HeaderImageUrl   = _products.GetItemTypeHeaderImg(_name)
                };

                var group = _itemGroup.Split(' '); string title = "";
                for (int i = 0; i < group.Count(); i++)
                {
                    title += group[i].First().ToString().ToUpper() + group[i].Substring(1).ToLower() + " ";
                }
                ;

                this.AddBreadCrumb(new BreadCrumb
                {
                    Title = title,
                    Url   = string.Format("?_name=" + _name + "&_itemGroup=" + _itemGroup + ""),
                    Order = 1
                });

                return(View(productmodel));
            }

            catch
            {
                return(RedirectToAction("Error", "Home", new { errorDetail = "Invalid Request" }));
            }
        }
 public ProductDetailsViewModel(Object listModel, IProductService productService)
 {
     this.service            = productService;
     selectedProductModel    = (ProductListModel)listModel;
     productID               = selectedProductModel.Id;
     this.product            = service.GetDataForDetailsView(productID);
     this.SaveDetailsCommand = new Command(SaveDetails);
     ProductName             = product.ProductName;
     ProductNumber           = product.ProductNumber;
     MakeFlag              = product.MakeFlag;
     FinishedGoodsFlag     = product.FinishedGoodsFlag;
     Color                 = product.Color;
     SafetyStockLevel      = product.SafetyStockLevel.ToString(); //short
     ReorderPoint          = product.ReorderPoint.ToString();     //short
     StandardCost          = product.StandardCost.ToString();     //decimal
     ListPrice             = product.ListPrice.ToString();        //decimal
     SizeUnitMeasureCode   = product.SizeUnitMeasureCode;
     WeightUnitMeasureCode = product.WeightUnitMeasureCode;
     Weight                = product.Weight.ToString();            //decimal
     DaysToManufacture     = product.DaysToManufacture.ToString(); //int
     ProductLine           = product.ProductLine;
     Class                 = product.Class;
     Style                 = product.Style;
     ProductSubcategoryID  = product.ProductSubcategoryID.ToString();
     ModelId               = product.ModelId.ToString();
     SellStartDate         = product.SellStartDate;
     SellEndDate           = product.SellEndDate;
 }
示例#24
0
        public ProductListModel FilterByPrice(IEnumerable <ProductIndexModel> PLModel, double PriceMin, double PriceMax)
        {
            if (PriceMin != 0 || PriceMax != 0)
            {
                List <ProductIndexModel> mdl = new List <ProductIndexModel>();

                foreach (var plm in PLModel)
                {
                    if (plm.Price > PriceMin && plm.Price < PriceMax)
                    {
                        mdl.Add(plm);
                    }
                }

                var productmodel = new ProductListModel
                {
                    ProductIndex = mdl,
                };

                return(productmodel);
            }

            else
            {
                var productmodel = new ProductListModel
                {
                    ProductIndex = PLModel,
                };

                return(productmodel);
            }
        }
示例#25
0
        public ActionResult ProductList(DataSourceRequest command, ProductListModel model)
        {
            if (!permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedView());
            }

            var categoryIds = new List <int>
            {
                model.SearchCategoryId
            };

            var products = productService.SearchProducts(
                categoryIds: categoryIds,
                keywords: model.SearchProductName,
                pageIndex: command.Page - 1,
                pageSize: command.PageSize
                );

            var gridModel = new DataSourceResult();

            gridModel.Data = products.Select(
                x =>
            {
                var productModel = x.ToModel();

                productModel.FullDescription = "";

                return(productModel);
            });
            gridModel.Total = products.TotalCount;

            return(Json(gridModel));
        }
示例#26
0
        public IActionResult Department(string department)
        {
            var userId = _userManager.GetUserId(User);

            if (userId != null)
            {
                var id = Int32.Parse(userId);

                var histid = _products.GetHistoryByUserId(id);

                var hist = _products.GetByHistoryId(histid);

                var model = hist.Select(a => new ProductModel
                {
                    ItemId = a.Id,
                    ManufacturerAndModel = _products.GetProductName(a.Id),
                    Model            = _products.GetModelName(a.Id),
                    FirstImage       = _products.GetFirstImage(a.Id),
                    Price            = a.Price,
                    AvrageUserRating = _products.GetAvrageRating(a.Id)
                });


                var productmodel = new ProductListModel
                {
                    ProductHistory = model
                };



                return(View(department, productmodel));
            }

            return(View(department));
        }
示例#27
0
        public ActionResult List()
        {
            var model = new ProductListModel();

            PrepareProductListModel(model);
            return(View(model));
        }
示例#28
0
        /// <summary>
        /// GET: Формирует список товаров
        /// </summary>
        /// <param name="minCost">Минимальная стоимость</param>
        /// <param name="maxCost">Максимальная стоимость</param>
        /// <param name="size">Размер товара</param>
        /// <returns>Список товаров</returns>
        public ActionResult ProductList(int?minCost, int?maxCost, Size?size)
        {
            var products           = ProductManager.GetList(minCost, maxCost, size);
            ProductListModel model = new ProductListModel(products);

            return(View(model));
        }
示例#29
0
        // GET: Product
        public async Task <ActionResult> Index()
        {
            string url = "";

            try
            {
                url = "http://localhost/StoreRest/api/product";
                using (HttpClient client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    client.DefaultRequestHeaders.Accept.Clear();
                    HttpResponseMessage response = await client.GetAsync(url);

                    if (response.IsSuccessStatusCode)
                    {
                        var p = await response.Content.ReadAsStringAsync();

                        ProductListModel s = new ProductListModel();
                        s.lpm = JsonConvert.DeserializeObject <List <ProductModel> >(p);
                        return(View(s.lpm));
                    }
                    else
                    {
                        ViewBag.Results = "0";
                        return(View(new List <ProductModel>()));
                    }
                } //end using System.Net.Http.HttpClient client
            }
            catch (Exception)
            {
                ViewBag.Results = "0";
                return(View(new List <ProductModel>()));
            }
        } //end public async Results method
        public JsonResult ProductList()
        {
            ProductListModel model = new ProductListModel();

            model.Products = productService.GetProductList().ToList();
            return(Json(model, JsonRequestBehavior.AllowGet));
        }