当前位置: 首页>>代码示例>>C#>>正文


C# ProductRepository.Get方法代码示例

本文整理汇总了C#中ProductRepository.Get方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.Get方法的具体用法?C# ProductRepository.Get怎么用?C# ProductRepository.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProductRepository的用法示例。


在下文中一共展示了ProductRepository.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Index

        // GET: Product
        public ActionResult Index(string sort = "Name", bool sortReverse = false, int pageNumber = 1, string searchFor = "")
        {
            ViewBag.CurrentSort = sortReverse;

            using (var productRep = new ProductRepository())
            {
                ViewBag.OnePageOfProducts = ((List<Product>)productRep.Get(sort, ViewBag.CurrentSort, searchFor)).ToPagedList(pageNumber, 10);
            }

            var allProducts = new List<ProductViewModel>();
            foreach (var item in ViewBag.OnePageOfProducts)
            {
                allProducts.Add(new ProductViewModel()
                {
                    Id = item.Id,
                    Name = item.Name,
                    Description = item.Description,
                    Preco = item.Preco,
                    PhotoOutput = item.Photo == null ? string.Empty : 
                        String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(item.Photo))
                });
            }

            ViewBag.AllProducts = allProducts;

            return View();
        }
开发者ID:fabiopsouza,项目名称:Learning.AspNetMVC,代码行数:28,代码来源:ProductController.cs

示例2: ProductRepositoryAddNewItemSaveItem

        public void ProductRepositoryAddNewItemSaveItem()
        {
            //Arrange
            var unitOfWork = new MainBCUnitOfWork();
            IProductRepository productRepository = new ProductRepository(unitOfWork);

            var book = new Book()
            {
                Id = IdentityGenerator.NewSequentialGuid(),
                ISBN = "ABC",
                Publisher = "Krasiss Press",
                Title = "The book title",
                UnitPrice = 40,
                Description = "Any book description",
                AmountInStock = 1
            };

            //Act

            productRepository.Add(book);
            productRepository.UnitOfWork.Commit();

            //Assert

            var result = productRepository.Get(book.Id);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id == book.Id);
        }
开发者ID:gabrielsimas,项目名称:MicrosoftNLayerApp,代码行数:29,代码来源:ProductRepositoryTests.cs

示例3: Index

        public ActionResult Index(int pageNumber = 1)
        {
            using (var productRep = new ProductRepository())
            {
                ViewBag.OnePageOfProducts = productRep.Get().ToPagedList(pageNumber, 8);
            }

            var allProducts = new List<ProductViewModel>();
            foreach (var item in ViewBag.OnePageOfProducts)
            {
                allProducts.Add(new ProductViewModel()
                {
                    Id = item.Id,
                    Name = item.Name,
                    Description = item.Description,
                    Preco = item.Preco,
                    PhotoOutput = item.Photo == null ? string.Empty :
                        String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(item.Photo))
                });
            }

            var countProducts = allProducts.Count();

            ViewBag.FirstRowOfProductList = countProducts.Equals(0) ? null : allProducts.Take(4);
            if (countProducts > 4)
                ViewBag.SecondRowOfProductList = countProducts.Equals(0) ? null : allProducts.GetRange(4, countProducts - 4);

            return View();
        }
开发者ID:fabiopsouza,项目名称:Learning.AspNetMVC,代码行数:29,代码来源:HomeController.cs

示例4: ProductRepositoryGetMethodReturnNullWhenIdIsEmpty

      public void ProductRepositoryGetMethodReturnNullWhenIdIsEmpty()
      {
         //Arrange
         var unitOfWork = new MainBcUnitOfWork();
         var productRepository = new ProductRepository(unitOfWork);

         Product product = null;

         //Act
         product = productRepository.Get(Guid.Empty);

         //Assert
         Assert.IsNull(product);
      }
开发者ID:MyLobin,项目名称:NLayerAppV2,代码行数:14,代码来源:ProductRepositoryTests.cs

示例5: ProductRepositoryGetMethodReturnMaterializedEntityById

      public void ProductRepositoryGetMethodReturnMaterializedEntityById()
      {
         //Arrange
         var unitOfWork = new MainBcUnitOfWork();
         IProductRepository productRepository = new ProductRepository(unitOfWork);

         var productId = new Guid("44668EBF-7B54-4431-8D61-C1298DB50857");
         Product product = null;

         //Act
         product = productRepository.Get(productId);

         //Assert
         Assert.IsNotNull(product);
         Assert.IsTrue(product.Id == productId);
      }
开发者ID:MyLobin,项目名称:NLayerAppV2,代码行数:16,代码来源:ProductRepositoryTests.cs

示例6: can_fetch_product

        public void can_fetch_product()
        {
            Product product = null;

            using(var session = _sessionFactory.Open())
            {
                var repo = new ProductRepository(session);
                product = repo.Get(1);
            }

            Assert.NotNull(product);

            Assert.NotNull(product.Description);
            Assert.NotNull(product.Name);
            Assert.NotNull(product.Price);

            Assert.NotNull(product.Brand);
            Assert.NotNull(product.Categories);
            Assert.NotNull(product.Colors);
            Assert.NotNull(product.Sizes);
        }
开发者ID:jaimalchohan,项目名称:2bit-coder-blog-code,代码行数:21,代码来源:ProductRepositoryTest.cs


注:本文中的ProductRepository.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。