public ActionResult ViewBook(int id = 0) { if (id == 0) //this should not happen { return(RedirectToAction("Index", "Home")); } var profile = (UserProfile)Session["UserInfo"]; using (var db = new SDCContext()) { ViewBag.Languages = db.Languages.Where(p => p.IsVisible).OrderBy(p => p.Code).ToList(); ViewBag.Genres = db.Genres.OrderBy(p => p.Name).ToList(); var book = db.Books .Include(b => b.Shelf) .Include(b => b.Shelf.Owner) .Include(b => b.Authors) .Include(b => b.Genres) .Include(b => b.Publisher) .Include(b => b.Pictures) .First(b => b.Id == id); bool showEditor = false; Boolean.TryParse(Request.QueryString["showEditor"], out showEditor); ViewBag.ShowEditor = showEditor; if (profile != null) { ViewBag.Breadcrumbs = Breadcrumb.Generate( "My shelves", Url.Action("Index", "Shelves"), book.Shelf.Name, Url.Action("Details", "Shelves", new { id = book.Shelf.Id }), book.Title, ""); } else { ViewBag.Breadcrumbs = Breadcrumb.Generate( book.Shelf.Name, Url.Action("Details", "Shelves", new { id = book.Shelf.Id }), book.Title, ""); } return(View(AutoMapper.Mapper.Map <BookViewModel>(book))); } }
public ActionResult Index() { UserProfile profile = ((UserProfile)Session["ProfileInfo"]); if (profile == null || profile.Role == RolesCustom.USER) { ViewBag.CanEdit = false; } else { ViewBag.CanEdit = true; } ViewBag.Breadcrumbs = Breadcrumb.Generate("Authors", ""); //these values may be missing from the query string. //these will be used by Datatables to "remember" the sorting ViewBag.ColSortIndex = Request.QueryString["col"]; ViewBag.ColSortDirection = Request.QueryString["ord"]; return(View()); }
public ActionResult Index() { ViewBag.Breadcrumbs = Breadcrumb.Generate( "My shelves", ""); var userProfile = (UserProfile)this.Session["UserInfo"]; if (userProfile == null) { return(RedirectToAction("Index", "Home")); } using (var db = new SDCContext()) { var shelves = (from s in db.Shelves orderby s.Name where s.Owner.UserId == userProfile.UserId select s).ToList(); var shelvesVMs = shelves.Select(s => { return(new ShelfViewModel() { Id = s.Id, Name = s.Name, CreationDate = s.CreationDate, IsVisible = s.IsVisible, BookCount = db.Entry(s).Collection(p => p.Books).Query().Count() }); }).ToArray(); return(View(new ShelvesViewModel() { Shelves = shelvesVMs })); } }
public ActionResult ViewAuthor(int id, int page = 1, int pagesize = 0) { if (id == 0) { return(RedirectToAction("Index", "Home")); } var profile = (UserProfile)this.Session["UserInfo"]; if (profile == null) { return(RedirectToAction("Index", "Home")); } if (pagesize < 1 || pagesize > 100) { pagesize = profile.PageSize; } using (var db = new SDCContext()) { profile.UpdatePageSize(db, pagesize); var author = db.Authors .Include(a => a.AddedBy) .Include(a => a.LastModifiedBy) .Include(a => a.Books) .FirstOrDefault(a => a.Id == id); if (author == null) { return(RedirectToAction("Index", "Home")); } int totalPages = ((int)Math.Ceiling((double)author.Books.Count / pagesize)); if (page > totalPages) { page = totalPages; } var model = AutoMapper.Mapper.Map <AuthorViewModel>(author); //actual pagination takes place here var show_books = author.Books .OrderBy(b => b.AddedDate) .Skip((page - 1) * pagesize) .Take(pagesize) .Select(b => AutoMapper.Mapper.Map <BookViewModel>(b)); model.Pagination = new PaginationViewModel() { Id = author.Id, Action = "ViewAuthor", Controller = "Authors", Page = page, PageSize = pagesize, TotalPages = totalPages, EntityCount = show_books.Count(), EntityName = "Books" }; ViewBag.Breadcrumbs = Breadcrumb.Generate( "Authors", Url.Action("Index", "Authors"), author.Name, ""); return(View(model)); } }
public ActionResult Details(int id, int page = 1, int pagesize = 0) { if (id == 0) { return(RedirectToAction("Index", "Home")); } var profile = (UserProfile)this.Session["UserInfo"]; if (profile == null) { return(RedirectToAction("Index", "Home")); } if (pagesize < 1 || pagesize > 100) { pagesize = profile.PageSize; } ShelfViewModel vm = null; using (var db = new SDCContext()) { profile.UpdatePageSize(db, pagesize); ViewBag.Languages = db.Languages.Where(p => p.IsVisible).OrderBy(p => p.Code).ToList(); ViewBag.Genres = db.Genres.OrderBy(p => p.Name).ToList(); var shelf = db.Shelves .AsNoTracking() .Include(a => a.Books) .Include(a => a.Books.Select(b => b.Pictures)) .Include(a => a.Books.Select(b => b.Authors)) .Include(a => a.Books.Select(b => b.Genres)) .Include(a => a.Books.Select(b => b.Publisher)) .FirstOrDefault(p => p.Id == id); if (shelf == null) { return(RedirectToAction("Index", "Home")); } int totalPages = ((int)Math.Ceiling((double)shelf.Books.Count / pagesize)); if (page > totalPages) { page = totalPages; } //actual pagination takes place here var show_books = shelf.Books .OrderBy(b => b.AddedDate) .Skip((page - 1) * pagesize) .Take(pagesize) .Select(b => AutoMapper.Mapper.Map <BookViewModel>(b)); vm = new ShelfViewModel() { Id = shelf.Id, Name = shelf.Name, IsVisible = shelf.IsVisible, CanEdit = shelf.CanBeEdited(profile), BookCount = shelf.Books.Count(), Books = show_books, Languages = Language.GetAll(db), Genres = Genre.GetAll(db), DefaultLanguage = profile.Country.Language, Pagination = new PaginationViewModel() { Id = shelf.Id, Action = "Details", Controller = "Shelves", Page = page, PageSize = pagesize, TotalPages = totalPages, EntityCount = show_books.Count(), EntityName = "Books" } }; if (profile.UserId == shelf.Owner.UserId) { ViewBag.Breadcrumbs = Breadcrumb.Generate( "My shelves", Url.Action("Index", "Shelves"), vm.Name, ""); } else { ViewBag.Breadcrumbs = Breadcrumb.Generate("Directory", "", vm.Name, ""); } db.Dispose(); } return(View(vm)); }