public IActionResult Detail(int?id) { if (id == null) { return(View("NoIdFound")); } var branch = _branch.GetBranchById((int)id); if (branch == null) { Response.StatusCode = 404; return(View("BranchNotFound", id)); } var model = new BranchDetailViewModel() { Id = branch.Id, Name = branch.Name, Address = branch.Address, Telephone = branch.Telephone, Description = branch.Description, OpenDate = branch.OpenDate.ToString("yyyy-MM-dd"), NumberOfAssets = _branch.GetAssets((int)id).Count(), NumberOfPatrons = _branch.GetPatrons((int)id).Count(), TotalAssetValue = _branch.GetAssets((int)id).Sum(x => x.Cost), ImageUrl = branch.ImageUrl, HoursOpen = _branch.GetBranchHours((int)id) }; return(View(model)); }
public async Task <IActionResult> Detail(int?id) { if (id == null) { return(View("NoIdFound")); } var branch = _branch.GetBranchById(id.Value); if (branch == null) { Response.StatusCode = 404; return(View("BranchNotFound", id)); } var model = _mapper.Map <BranchDetailViewModel>(branch); model.HoursOpen = _branch.GetBranchHours(id.Value); var branchAssets = await _branch.GetAssetsAsync(id.Value); model.NumberOfAssets = branchAssets.Count(); model.TotalAssetValue = branchAssets.Sum(x => x.Cost); model.NumberOfPatrons = (await _branch.GetPatronsAsync(id.Value)).Count(); return(View(model)); }