public ActionResult History(int bookId) { var bookRepo = new BookRepository(); var readers = new List<Reader>(); var book = bookRepo.Find(bookId); readers = book.Orders.Select(o => o.Reader).ToList<Reader>(); if (!User.IsInRole("Admin")) { readers = readers.Where(r => r.UserName == User.Identity.Name).ToList(); } return View(readers); }
public ActionResult Index() { ViewBag.Message = "Web library"; var repo = new BookRepository(); //var books = new List<Book>(); var books = new ShowBooksViewModel(); if (Request.IsAuthenticated) { books.ForOrder = repo.GetAllExceptOrderedBy(User.Identity.Name); books.InUse = repo.GetBooksOrderedBy(User.Identity.Name); } else { books.ForOrder = repo.GetInStockBooks(); } return View(books); }
public ActionResult Create(string title, int quantity, int authorId) { if (title.Length < 1 || quantity < 0) { throw new ArgumentOutOfRangeException(); } var authorRepo = new AuthorRepository(); var bookToAdd = new Book(); bookToAdd.Title = title; bookToAdd.Quantity = quantity; var bookRepo = new BookRepository(); bookRepo.AddBook(bookToAdd); authorRepo.AddBookToAuthor(authorId, bookToAdd); return RedirectToAction("Create"); }