public async Task <ActionResult> Index() { using (var db = new EbookManagerDbContext()) { var catalogRepository = new CatalogRepository(db); var ebooks = await catalogRepository.LoadCatalogAsync(); var model = new AdminCatalogModel(); model.Ebooks = ebooks.Select(e => EbookViewModel.FromEbook(e)).ToList(); return(View(model)); } }
public async Task <ActionResult> Index() { using (var db = new EbookManagerDbContext()) { var catalogRepository = new CatalogRepository(db); var ebooks = await catalogRepository.LoadCatalogWithoutPartsAsync(); var model = new CatalogViewModel(); model.Ebooks.AddRange(ebooks.Select(e => EbookViewModel.FromEbook(e))); return(View(model)); } }
public async Task <ActionResult> Index() { using (var db = new EbookManagerDbContext()) { var userName = User.Identity.Name; var catalogRepository = new CatalogRepository(db); var ebooks = await catalogRepository.LoadUserCatalog(userName); var model = new CatalogViewModel(); model.Ebooks.AddRange(ebooks.Select(e => EbookViewModel.FromEbook(e))); return(View(model)); } }
public async Task <ActionResult> DeleteBook(Guid ebookId) { using (var db = new EbookManagerDbContext()) { var catalogRepository = new CatalogRepository(db); var ebook = await catalogRepository.GetEbookAsync(ebookId); if (ebook == null) { throw new HttpException(404, "not found"); } var model = EbookViewModel.FromEbook(ebook); return(View(model)); } }
public async Task <ActionResult> Details(Guid ebookId) { using (var db = new EbookManagerDbContext()) { var catalogRepository = new CatalogRepository(db); var ebook = await catalogRepository.GetEbookAsync(ebookId); var model = EbookViewModel.FromEbook(ebook); var userId = ClaimsPrincipal.Current.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value; ViewBag.UserOwnsBook = await catalogRepository.UserOwnsBookAsync(userId, ebookId); return(View(model)); } }