Esempio n. 1
0
        public IActionResult Checkout(int?id)
        {
            var  BookId     = id;
            var  LibraryCtx = new BookishContext();
            Book book       = LibraryCtx.Books.Find(BookId);

            if (book == null)
            {
                return(RedirectToAction("Error"));
            }
            List <Copy>                copies       = LibraryCtx.Copies.Where(b => b.Book == book).ToList();
            List <Checkout>            checkouts    = new List <Checkout>();
            CheckoutCatalogueViewModel CheckoutList = new CheckoutCatalogueViewModel();

            foreach (var copy in copies)
            {
                foreach (var check in checkouts)
                {
                    if (check.Copy == copy)
                    {
                        checkouts.Add(check);
                    }
                }
            }
            CheckoutList.CheckoutCatalogue = checkouts.ToList();
            return(View(CheckoutList));
        }
Esempio n. 2
0
        public IActionResult Checkout(int?id)
        {
            // var BookId = id;
            // var LibraryCtx = new BookishContext();
            // Book book = LibraryCtx.Books.Find(BookId);
            // if (book == null)
            // {
            //     return RedirectToAction("Error");
            // }
            // List<Copy> copies = LibraryCtx.Copies.Where(b => b.Book == book).ToList();
            // List<Checkout> checkouts=new List<Checkout>();
            // CheckoutCatalogueViewModel CheckoutList = new CheckoutCatalogueViewModel();

            // foreach (var copy in copies)
            // {
            //     foreach (var check in checkouts)
            //     {
            //         if (check.Copy==copy)
            //         {
            //             checkouts.Add(check);
            //         }
            //     }
            // }
            // CheckoutList.CheckoutCatalogue = checkouts.ToList();
            // return View(CheckoutList);

            var  CopyId     = id;
            var  LibraryCtx = new BookishContext();
            Copy copy       = LibraryCtx.Copies.Find(CopyId);

            if (copy == null)
            {
                return(RedirectToAction("Error"));
            }

            CheckoutCatalogueViewModel CheckoutList = new CheckoutCatalogueViewModel();
            var checkouts = LibraryCtx.Checkouts.Where(c => c.Copy.CopyId == CopyId)
                            .Include(c => c.Copy)
                            .Include(c => c.Copy.Book)
                            .Include(c => c.Member);

            CheckoutList.CheckoutCatalogue = checkouts.ToList();
            return(View(CheckoutList));
        }
Esempio n. 3
0
        public IActionResult Account(int?id)
        {
            var    MemberId   = id;
            var    LibraryCtx = new BookishContext();
            Member member     = LibraryCtx.Members.Find(MemberId);

            if (member == null)
            {
                return(RedirectToAction("Error"));
            }

            var CheckoutsWithCopies = LibraryCtx.Checkouts.Where(c => c.Member == member)
                                      .Include(c => c.Copy)
                                      .Include(c => c.Copy.Book);
            List <Checkout>            checkouts    = CheckoutsWithCopies.ToList();
            CheckoutCatalogueViewModel CheckoutList = new CheckoutCatalogueViewModel();

            CheckoutList.CheckoutCatalogue = checkouts;

            return(View(CheckoutList));
        }