// GET
        public IActionResult Index(int?authorId, int?borrowerId)
        {
            if (authorId == null && borrowerId == null)
            {
                //show All Books
                var books = new BookHandler().GetBookswithAuthor();
                return(CheckBookCount(books));
            }
            else if (authorId != null)
            {
                //filter by Author By Id
                var author = new AuthorHandler().GetAuthorwithBooksById((int)authorId);
                if (author.Books.Count == 0)
                {
                    return(View("AuthorEmpty", author));
                }
                else
                {
                    return(View(author.Books));
                }
            }
            else if (borrowerId != null)
            {
                var books = new BookHandler().GetBookwithAuthorandBorrowerById((int)borrowerId);
                return(CheckBookCount(books));
            }
            else
            {
                throw new ArgumentException();
            }

            return(View());
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {

            var bookhandler = new BookHandler().GetBookwithAuthorBorrower(x => x.Customer.CustomerId != 0);
            if (bookhandler == null || bookhandler.ToList().Count == 0)
            {
                return View("Empty");
            }
            return View(bookhandler);
        }
Ejemplo n.º 3
0
        // GET
        public IActionResult Index()
        {
            var availableBooks = new BookHandler().GetBookwithAuthorBorrower(x => x.Customer.CustomerId == 0);

            if (availableBooks.Count == 0)
            {
                return(View("Empty"));
            }

            return(View(availableBooks));
        }
        public IActionResult DeleteBook(int id)
        {
            var builder = new DbContextOptionsBuilder <LibraryContext>();
            var db      = new LibraryContext(builder.Options);

            var book = new BookHandler().GetBookById(id);

            if (book != null)
            {
                db.Entry(book).State = EntityState.Deleted;
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            //Heater heater = new Heater();
            //Alarm alarm = new Alarm();
            //heater.BoilEvent += alarm.MakeAlert;//注册方法
            //heater.BoilEvent += (new Alarm()).MakeAlert;//给匿名对象注册方法
            //heater.BoilEvent += Display.ShowMsg;    //注册静态方法
            //heater.BoilWater();
            //Console.ReadKey();
            BookStore store = new BookStore();
            Customer  c1    = new Customer();

            BookHandler bookhandler = new BookHandler(c1.store_OnNewBook);
            Customer    c           = new Customer()

                                      Console.ReadKey();
        }
Ejemplo n.º 6
0
        public IActionResult ReturnBook(int bookId)
        {
            var book = new BookHandler().GetBookById(bookId);

            book.Customer = null;


            var builder = new DbContextOptionsBuilder<LibraryContext>();
            var db = new LibraryContext(builder.Options);
            using (db)
            {
                db.Entry(book).State = EntityState.Modified;
                db.SaveChanges();
            }

            return RedirectToAction("index");
        }
Ejemplo n.º 7
0
        public IActionResult LendBook(LendViewModel lendViewModel)
        {
            var book     = new BookHandler().GetBookById(lendViewModel.Book.BookId);
            var customer = new CustomerHandler().GetCustomerById(lendViewModel.Book.Customer.CustomerId);

            book.Customer = customer;
            var builder = new DbContextOptionsBuilder <LibraryContext>();
            var db      = new LibraryContext(builder.Options);

            using (db)
            {
                db.Entry(book).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public void Insert()
        {
            var repositoryMock = new Mock <IBookRepository>();

            repositoryMock.Setup(x => x.Insert(It.IsAny <Book>())).Returns((Book x) => x);

            var handler = new BookHandler(repositoryMock.Object);

            var idAuthor = Guid.NewGuid();
            var book     = handler.Insert(new InsertBookCommand()
            {
                Title    = "Title",
                Synopsis = "Synopsis",
                AuthorId = idAuthor
            });

            book.Title.ShouldBe("Title");
            book.Synopsis.ShouldBe("Synopsis");
            book.AuthorId.ShouldBe(idAuthor);
        }
Ejemplo n.º 9
0
 private void Start()
 {
     m_handbook = GameObject.FindGameObjectWithTag("Handbook").GetComponent <BookHandler>();
 }
Ejemplo n.º 10
0
 private void Awake()
 {
     mainCamera    = Camera.main;
     bookComponent = codexBook.GetComponent <BookHandler>();
 }
Ejemplo n.º 11
0
 public BookService(BookHandler bookHandler)
 {
     _bookHandler = bookHandler;
 }
Ejemplo n.º 12
0
 public BookController(IBookRepository repository, BookHandler handler)
 {
     _repository = repository;
     _handler    = handler;
 }
Ejemplo n.º 13
0
 public BookController(BookHandler bookHandler, IBookRepository bookRepository, IMemoryCache cache)
 {
     _bookHandler    = bookHandler;
     _bookRepository = bookRepository;
     _cache          = cache;
 }