Example #1
0
 public void Dispose()
 {
     if (_db != null)
     {
         _db.Dispose();
         _db = null;
     }
 }
        public GetById(ITestOutputHelper output)
        {
            _output = output;
            var dbOptions = new DbContextOptionsBuilder <ProductCategoryContext>()
                            .UseInMemoryDatabase(databaseName: "TestProductCategory")
                            .Options;

            _productCategoryContext = new ProductCategoryContext(dbOptions);
            _categoryRepository     = new CategoryRepository(_productCategoryContext);
        }
        public IQueryable <ListOfProducts> GetProducts([QueryString("id")] int?categoryId, [RouteData] string categoryName)
        {
            var _db = new ProductCategoryContext();
            IQueryable <ListOfProducts> query = _db.Products;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }

            /* if (!string.IsNullOrEmpty(categoryName))
             * {
             *   query = query.Where(p => string.Compare(p.Category.CategoryName, categoryName) == 0);
             * }*/

            return(query);
        }
Example #4
0
 // Creates dbContext each time the controller is accessed
 public MainController(ProductCategoryContext context)
 {
     dbContext = context;
 }