예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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");
        }