public CategoryBooksViewModel GetCategoryBooks(int category) { IEnumerable <Category> categories = _categoryRepository.GetCategoryBooks(category); CategoryBooksViewModel categoryBooksViewModel = Mapper.Map <IEnumerable <Category>, CategoryBooksViewModel>(categories); return(categoryBooksViewModel); }
public IActionResult GetCategoryById(int categoryId) { var category = _categoryRepository.GetCategoryById(categoryId); if (category == null) { ModelState.AddModelError("", "Error getting a category"); ViewBag.Message = $"There was a problem retrieving category with id {categoryId} " + $"From the database or no category with that id exists"; category = new CategoryDto(); } var books = _categoryRepository.GetAllBooksForCategory(categoryId); if (books.Count() <= 0) { ViewBag.BookMessage = $"{category.Name} has no books"; } var bookCategoryViewModel = new CategoryBooksViewModel() { Category = category, Books = books }; // because of create / update / delete method so we have to have it ViewBag.SuccessMessage = TempData["SuccessMessage"]; return(View(bookCategoryViewModel)); }
public IActionResult GetCategoryById(int categoryId) { var category = _categoryRepository.GetCategoryById(categoryId); if (category == null) { ModelState.AddModelError("", $"There is no category with id:{categoryId}"); ViewBag.Message = $"There was a problem retrieving category with id {categoryId} " + $"from the database or no category exists"; category = new CategoryDto(); } var books = _categoryRepository.GetAllBooksForCategory(categoryId); if (books.Count() <= 0) { ViewBag.BookMessage = $"Category: {category.Name} has no books"; } var bookCategoryViewModel = new CategoryBooksViewModel() { Category = category, Books = books }; return(View(bookCategoryViewModel)); }
public IActionResult Detail(int categoryId) { var category = categoriesRepository.GetCategory(categoryId); if (category == null) { ModelState.AddModelError("", "Error getting a country"); ViewBag.Message = $"There was a problem retrieving country id {categoryId}" + $" from the database or no country with id {categoryId} exists."; category = new CategoryDto(); } var books = categoriesRepository.GetAllBooksPerCategory(categoryId); if (books.Count() <= 0) { ViewBag.BookMessage = $"{category.Name} has no books."; } var categoryViewModel = new CategoryBooksViewModel() { Category = category, Books = books }; return(View(categoryViewModel)); }
public async Task <ActionResult> GetCategoryById(int categoryId) { var category = await _categoryRepositoryGUI.GetCategoryById(categoryId); if (category == null) { ModelState.AddModelError("", "Error getting a category"); ViewBag.Message = $"ID {categoryId}'s category did not exist in database"; category = new CategoryDto(); } var books = await _categoryRepositoryGUI.GetBooksFromACategory(categoryId); if (books.Count() <= 0) { ViewBag.BookMessage = $"{category.Name} did not have any books"; } var bookCategory = new CategoryBooksViewModel { Category = category, Books = books }; return(View(bookCategory)); }