public ProductController(StockDataRepository <Products> dataRepository) { _dataRepository = dataRepository; IEnumerable <Products> products = _dataRepository.GetAll(); bool hasElements = products.Any(); if (!hasElements) { var product1 = new Products { //Id = 1, Model = "Mazda 3", Description = "New Model", Year = 2018, Brand = "Mazda", Kilometers = 100, Price = 320689 }; var product2 = new Products { //Id = 2, Model = "KIA Forte", Description = "Innovation", Year = 2019, Brand = "KIA", Kilometers = 68, Price = 378569 }; _dataRepository.Add(product1); _dataRepository.Add(product2); } }
public IActionResult Get() { IEnumerable <Products> products = _dataRepository.GetAll(); return(Ok(products)); }