Exemple #1
0
        public void ProductServiceContext_NotNull()
        {
            //Act
            var result = new ProductServiceContext();

            //Assert
            Assert.IsNotNull(result);
        }
Exemple #2
0
        public List <Product> GetAllProducts()
        {
            using (ProductServiceContext ctx = new ProductServiceContext())
            {
                products = ctx.Product.ToList();
            };

            return(products);
        }
Exemple #3
0
        public void ProductServiceContext_HasNotNullProducts()
        {
            //Arrange
            var context = new ProductServiceContext();
            //Act
            var result = context.Products;

            //Assert
            Assert.IsNotNull(result);
        }
Exemple #4
0
        public Product GetById(int id)
        {
            Product product;

            using (ProductServiceContext ctx = new ProductServiceContext())
            {
                product = ctx.Product.FirstOrDefault(x => x.Id == id);
            };

            return(product);
        }
Exemple #5
0
        public ProductVM GetProductVM(int id)
        {
            ProductVM productVM = new ProductVM();

            using (ProductServiceContext ctx = new ProductServiceContext())
            {
                productVM.product            = ctx.Product.FirstOrDefault(x => x.Id == id);
                productVM.productInformation = ctx.ProductInformation.FirstOrDefault(x => x.Keyboard_Id == id);
            };

            return(productVM);
        }
Exemple #6
0
        public ProductInformation GetInfoById(int id)
        {
            ProductInformation productInfo;

            using (ProductServiceContext ctx = new ProductServiceContext())
            {
                var products = ctx.ProductInformation.ToList();
                productInfo = ctx.ProductInformation.FirstOrDefault(x => x.Keyboard_Id == id);
            };

            return(new ProductInformation());
        }
 private void GetCategories(ProductServiceContext context)
 {
     context.Categories.AddOrUpdate(x => x.Id,
                                    new Category()
     {
         Id = 1, Name = "Cocktails"
     },
                                    new Category()
     {
         Id = 2, Name = "Beers"
     },
                                    new Category()
     {
         Id = 3, Name = "Wines"
     },
                                    new Category()
     {
         Id = 4, Name = "Spirits"
     }
                                    );
 }
        private void GetProducts(ProductServiceContext context)
        {
            //TODO: Replace file path with the directory you are running the code from.
            string jsonFilePath   = @"C:\Users\fiona.mccartney\Source\Repos\ProductService\ProductService\App_Data\products.json";
            string productJsonAll = GetEmbeddedResourceAsString(jsonFilePath);

            JArray  jsonValProducts = JArray.Parse(productJsonAll) as JArray;
            dynamic productsData    = jsonValProducts;

            foreach (dynamic product in productsData)
            {
                context.Products.AddOrUpdate(x => x.Id,
                                             new Product
                {
                    Id          = product.id,
                    Name        = product.name,
                    Description = product.description,
                    CategoryId  = product.categoryId
                }
                                             );
            }
        }
Exemple #9
0
 public ProductsController(ProductServiceContext repository)
 {
     _repository = repository;
 }
Exemple #10
0
 public ProductsController()
 {
     _repository = new ProductServiceContext();
 }
Exemple #11
0
 public CategoriesController(ProductServiceContext repository)
 {
     _repository = repository;
 }
Exemple #12
0
 public CategoriesController()
 {
     _repository = new ProductServiceContext();
 }