// GET: Books/Details/5 public async Task <IActionResult> Details(string id) { if (id == null) { return(NotFound()); } var book = await _bc.FindByIdAsync(id); if (book == null) { return(NotFound()); } TempData["AvailableCopies"] = await _bc.GetNoOfAvailableModelCopies(book); return(View(book)); }
public async Task <IActionResult> Index() { Client client = await _cm.FindByEmailAsync(User.Identity.Name); int borrowMax = client.BorrowMax; int numModels = await _identityMap.CountModelCopiesOfClient(client.clientId); int cartCount = HttpContext.Session.GetInt32("ItemsCount") ?? 0; List <SessionModel> Items = HttpContext.Session.GetObject <List <SessionModel> >("Items") ?? new List <SessionModel>(); TempData["totalBorrowed"] = cartCount + numModels; TempData["canBorrow"] = cartCount + numModels <= borrowMax; TempData["borrowMax"] = borrowMax; List <Task <Book> > bookTasks = new List <Task <Book> >(Items.Count); List <Task <Magazine> > magazineTasks = new List <Task <Magazine> >(Items.Count); List <Task <Movie> > movieTasks = new List <Task <Movie> >(Items.Count); List <Task <Music> > musicTasks = new List <Task <Music> >(Items.Count); foreach (SessionModel element in Items) { switch (element.ModelType) { case TypeEnum.Book: { bookTasks.Add(_bookc.FindByIdAsync(element.Id.ToString())); break; } case TypeEnum.Magazine: { magazineTasks.Add(_magazinec.FindByIdAsync(element.Id.ToString())); break; } case TypeEnum.Movie: { movieTasks.Add(_moviec.GetMovieByIdAsync(element.Id)); break; } case TypeEnum.Music: { musicTasks.Add(_musicc.FindMusicByIdAsync(element.Id.ToString())); break; } } } List <CartViewModel> result = new List <CartViewModel>(Items.Count); result.AddRange(bookTasks.Select(t => { t.Wait(); Book b = t.Result; return(new CartViewModel { ModelId = b.BookId, Title = b.Title, Type = TypeEnum.Book }); })); result.AddRange(magazineTasks.Select(t => { t.Wait(); Magazine m = t.Result; return(new CartViewModel { ModelId = m.MagazineId, Title = m.Title, Type = TypeEnum.Magazine }); })); result.AddRange(movieTasks.Select(t => { t.Wait(); Movie m = t.Result; return(new CartViewModel { ModelId = m.MovieId, Title = m.Title, Type = TypeEnum.Movie }); })); result.AddRange(musicTasks.Select(t => { t.Wait(); Music m = t.Result; return(new CartViewModel { ModelId = m.MusicId, Title = m.Title, Type = TypeEnum.Music }); })); return(View(result)); }