public List <ProductGetModel> GetAllByCategoryId(int categoryId, User currentUser) { var existingCategory = this.categoryService.GetById(categoryId, currentUser); if (existingCategory == null) { return(null); } return(context.Products .Where(p => p.CategoryId == categoryId) .Select(p => ProductGetModel.DtoFromModel(p)).ToList()); }
public IActionResult GetProduct(int id) { var cat = _dataService.GetProduct(id); if (cat == null) { return(NotFound()); } var _out = new ProductGetModel { Name = cat.Name, CategoryName = cat.Category.Name }; return(Ok(_out)); }