//Returns the details for a selected asset public IActionResult Detail(int id) { //Selects the required asset LibraryAsset asset = _assets.GetById(id); var currentHolds = _checkouts.GetCurrentHolds(id) .Select(a => new AssetHoldModel { HoldPlaced = _checkouts.GetCurrentHoldPlaced(a.Id).ToString("d"), PatronName = _checkouts.GetCurrentHoldPatronName(a.Id) }); var currentCheckoutHistory = _checkouts.GetCheckoutHistory(id) .Select(a => new AssetCheckoutHistoryModel { Id = id, PatronName = _checkouts.GetCurrentCheckedOutPatronName(a.Id), CheckedOut = _checkouts.CheckedOut(a.Id), CheckedIn = _checkouts.CheckedIn(a.Id), LibraryCardId = a.LibraryCard.Id }); //Creates the ViewModel //Populate the AssetDetail model with: // LibraryAsset properties OR // services from the _assets ILibrary service AssetDetailModel model = new AssetDetailModel() { AssetId = id, Title = asset.Title, Year = asset.Year, Status = asset.Status.Name, Cost = asset.Cost, ImageUrl = asset.ImageUrl, AuthorOrDirector = _assets.GetAuthorOrDirector(id), CurrentLocation = _assets.GetCurrentLocation(id).Name, Type = _assets.GetType(id), DeweyCallNumber = _assets.GetDeweyIndex(id), ISBN = _assets.GetIsbn(id), CheckoutHistory = _checkouts.GetCheckoutHistory(id), LatestCheckOut = _checkouts.GetLatestCheckout(id), PatronName = _checkouts.GetCurrentCheckoutPatron(id), CurrentHolds = currentHolds, CurrentCheckoutHistory = currentCheckoutHistory }; return(View(model)); }