예제 #1
0
        public IActionResult CopyInsert(CopyAdd newCopies)
        {
            // select from book where book id is the value entered by the user
            var contextBook = new BookishContext();
            var booklist    = contextBook.Books
                              .Where(s => s.BookId == newCopies.BookId)
                              .ToList();

            // if you get a value do the insert below
            if (booklist.Count == 1)
            {
                using (var context = new BookishContext())
                {
                    // move the values obtained from the form to the variable book

                    for (var i = 0; i < newCopies.NumberofCopies; i++)
                    {
                        var copies = new Copy()
                        {
                            BookId = newCopies.BookId
                        };
                        context.Copies_Book_Member.Add(copies);
                        context.SaveChanges();
                    }
                }
                return(RedirectToAction("CopyAdd"));
            }
            else
            {
                return(RedirectToAction("CopyAddError"));
            }
        }
예제 #2
0
        public IActionResult CheckoutCopy(int copyid, int memberid)
        {
            var    CopyId           = copyid;
            var    MemberId         = memberid;
            Copy   CopyToCheckout   = new Copy();
            Member MemberToCheckout = new Member();

            using (var LibraryCtx = new BookishContext()) {
                // change this copy to being checked out
                CopyToCheckout            = LibraryCtx.Copies.Find(CopyId);
                CopyToCheckout.CheckedOut = true;

                MemberToCheckout = LibraryCtx.Members.Find(MemberId);
                Checkout NewCheckout = new Checkout();
                NewCheckout.Copy         = CopyToCheckout;
                NewCheckout.Member       = MemberToCheckout;
                NewCheckout.CheckoutDate = DateTime.Now;
                NewCheckout.DueDate      = DateTime.Now.AddDays(14);
                NewCheckout.Returned     = false;

                LibraryCtx.Checkouts.Add(NewCheckout);
                LibraryCtx.SaveChanges();

                // want to get the bookID of the copy, something like Copy.Book.BookId
                var BookToDisplay = LibraryCtx.Copies.Where(c => c.CopyId == copyid).Include(c => c.Book).First();
                return(RedirectToAction("Details", new { id = BookToDisplay.Book.BookId }));
            }
        }
예제 #3
0
        public IActionResult AddBook(Book newbook)
        {
            using (var LibraryCtx = new BookishContext())
            {
                bool BookExists = LibraryCtx.Books.Any(b => b.Title == newbook.Title && b.Author == newbook.Author && b.Year == newbook.Year);

                // if book is not already in catalogue, add it
                if (!BookExists)
                {
                    LibraryCtx.Books.Add(newbook);
                    Copy NewCopy = new Copy();
                    NewCopy.Book       = newbook;
                    NewCopy.CheckedOut = false;
                    LibraryCtx.Copies.Add(NewCopy);
                }
                else
                {
                    Copy NewCopy  = new Copy();
                    Book SameBook = LibraryCtx.Books.Where(b => b.Title == newbook.Title && b.Author == newbook.Author && b.Year == newbook.Year).ToList().First();
                    NewCopy.Book = SameBook;
                    // NewCopy.Book = the book already in the catalogue
                    NewCopy.CheckedOut = false;
                    LibraryCtx.Copies.Add(NewCopy);
                }

                LibraryCtx.SaveChanges();
            }
            return(RedirectToAction("AddBook"));
        }
예제 #4
0
        public IActionResult Checkout(String CopyId, String BookId, String MemberId)
        {
            //copy has to be populated
            // var context = new BookishContext();
            // var copy = context.Copies_Book_Member
            //                     .Where(s => s.CopyId == Int32.Parse(CopyId))
            //                     .ToList()

            var copy = new Copy()
            {
                CopyId = Int32.Parse(CopyId), BookId = Int32.Parse(BookId)
            };

            // MemberId = Int32.Parse(MemberId), IssueDate = DateTime.Now, DueDate = DateTime.Now.AddDays(14)

            copy.MemberId  = Int32.Parse(MemberId);
            copy.IssueDate = DateTime.Now;
            copy.DueDate   = DateTime.Now.AddDays(14);

            using (var context = new BookishContext())
            {
                context.Update <Copy>(copy);
                context.SaveChanges();
            }

            return(RedirectToAction("FindCopies"));
        }
예제 #5
0
        public IActionResult BookSearchList(String BookId, String TitleP, String Title, String Author, String Year)
        {
            // Console.WriteLine(book.Title.GetType());
            var context  = new BookishContext();
            var booklist = context.Books.AsQueryable();

            if (!String.IsNullOrEmpty(BookId))
            {
                booklist = booklist.Where(s => s.BookId == Int32.Parse(BookId));
            }
            if (!String.IsNullOrEmpty(TitleP))
            {
                booklist = booklist.Where(s => s.Title.Contains(TitleP));
            }
            if (!String.IsNullOrEmpty(Title))
            {
                booklist = booklist.Where(s => s.Title == Title);
            }
            if (!String.IsNullOrEmpty(Author))
            {
                booklist = booklist.Where(s => s.Author.Contains(Author));
            }
            if (!String.IsNullOrEmpty(Year))
            {
                booklist = booklist.Where(s => s.Year == Int32.Parse(Year));
            }
            var books = booklist.OrderBy(x => x.Title).ToList();
            var list  = new BookListViewModel(books);

            return(View(list));
            // return RedirectToAction ("BookList");
        }
예제 #6
0
        public IActionResult SearchOneUser(string search)
        {
            var context = new BookishContext();
            List <UserModel> users;

            if (!String.IsNullOrEmpty(search))
            {
                DateTime dob;
                if (DateTime.TryParse(search, out dob))
                {
                    users = context.UserModel.Where(x => x.UserDOB == dob).ToList();
                }
                else
                {
                    users = context.UserModel.Where(x => x.UserName == search).ToList();
                }
            }
            else
            {
                users = context.UserModel.ToList();
            }
            var userlist = new UserListModel {
                UserList = users
            };

            return(View(userlist));
        }
예제 #7
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));
        }
예제 #8
0
 public IActionResult AddMember(Member newmember)
 {
     using (var LibraryCtx = new BookishContext())
     {
         LibraryCtx.Members.Add(newmember);
         LibraryCtx.SaveChanges();
     }
     return(RedirectToAction("AddMember"));
 }
예제 #9
0
        public IActionResult AddOneBookFormMethod(BookModel book)
        {
            var context = new BookishContext();

            context.BookModel.Add(book);
            context.SaveChanges();

            return(RedirectToAction(nameof(AddOneBook)));
        }
예제 #10
0
        [HttpPost("addOneUserToDB")] //can we leave this empty since its not taking us to a page?
        public IActionResult AddOneUserFormMethod(UserModel user)
        {
            var context = new BookishContext();

            context.UserModel.Add(user);
            context.SaveChanges();

            return(RedirectToAction(nameof(AddOneUser)));
        }
예제 #11
0
        public IActionResult MemberList()
        {
            var context    = new BookishContext();
            var memberlist = context.Members

                             .ToList();
            var list = new MemberListViewModel(memberlist);

            return(View(list));
        }
예제 #12
0
        public IActionResult UpdateMemberInfo(String MemberId)

        {
            var context    = new BookishContext();
            var memberlist = context.Members
                             .Where(s => s.MemberId == Int32.Parse(MemberId))
                             .ToList();
            var member = memberlist[0];

            return(View(member));
        }
예제 #13
0
        public IActionResult CheckoutCopy(int?id)
        {
            var  CopyId         = id;
            Copy CopyToCheckout = new Copy();

            using (var LibraryCtx = new BookishContext())
            {
                CopyToCheckout = LibraryCtx.Copies.Find(CopyId);
                return(View(CopyToCheckout));
            }
        }
예제 #14
0
        public IActionResult Index()
        {
            MemberCatalogueViewModel MemberList = new MemberCatalogueViewModel();

            using (var LibraryCtx = new BookishContext())
            {
                MemberList.MemberCatalogue = LibraryCtx.Members.Take(10).ToList();
            }

            return(View(MemberList));
        }
예제 #15
0
        public IActionResult BookList()
        {
            var context  = new BookishContext();
            var booklist = context.Books
                           .OrderBy(x => x.Title)
                           .ToList();

            var list = new BookListViewModel(booklist);

            return(View(list));
        }
예제 #16
0
        public IActionResult Delete(int?id, bool?saveChangesError = false)
        {
            var  BookId     = id;
            var  LibraryCtx = new BookishContext();
            Book book       = LibraryCtx.Books.Find(BookId);

            if (book == null)
            {
                return(RedirectToAction("Error"));
            }
            return(View(book));
        }
예제 #17
0
        public IActionResult Delete(int?id, bool?saveChangesError = false)
        {
            var    MemberId   = id;
            var    LibraryCtx = new BookishContext();
            Member member     = LibraryCtx.Members.Find(MemberId);

            if (member == null)
            {
                return(RedirectToAction("Error"));
            }
            return(View(member));
        }
예제 #18
0
        public IActionResult AddCopy(int?id)
        {
            var  BookId     = id;
            var  LibraryCtx = new BookishContext();
            Book book       = LibraryCtx.Books.Find(BookId);

            if (book == null)
            {
                return(RedirectToAction("Error"));
            }
            return(View(book));
        }
예제 #19
0
        public IActionResult Delete(int id)
        {
            var context = new BookishContext();
            var user    = context.UserModel.Find(id); //why not user.id?

            if (user != null)
            {
                context.UserModel.Remove(user);
                context.SaveChanges();
            }
            return(RedirectToAction(nameof(UserSearch)));
        }
예제 #20
0
        public IActionResult Edit(int?id)
        {
            var    MemberId   = id;
            var    LibraryCtx = new BookishContext();
            Member member     = LibraryCtx.Members.Find(MemberId);

            if (member == null)
            {
                return(RedirectToAction("Error"));
            }
            return(View(member));
        }
예제 #21
0
        public IActionResult ListOfBorrowers(int search)
        {
            var context = new BookishContext();
            List <BookCheckedOutModel> checkedOutBook;

            checkedOutBook = context.BookCheckedOutModel.Where(x => x.BookId == search).ToList();

            var checkedOutBookList = new BookCheckedOutListModel {
                BookCheckedOutList = checkedOutBook
            };

            return(View(checkedOutBookList));
        }
예제 #22
0
        public IActionResult Edit(Book book)
        {
            using (var LibraryCtx = new BookishContext())
            {
                var  BookId       = book.BookId;
                Book bookToUpdate = LibraryCtx.Books.Find(BookId);
                bookToUpdate.Title  = book.Title;
                bookToUpdate.Author = book.Author;
                bookToUpdate.Year   = book.Year;
                LibraryCtx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
예제 #23
0
        public IActionResult Delete(int id)
        {
            var    MemberId   = id;
            var    LibraryCtx = new BookishContext();
            Member member     = LibraryCtx.Members.Find(MemberId);

            LibraryCtx.Members.Remove(member);
            List <Checkout> checkouts = LibraryCtx.Checkouts.Where(m => m.Member == member).ToList();

            LibraryCtx.Checkouts.RemoveRange(checkouts);

            LibraryCtx.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #24
0
        public IActionResult MemberBookList(FindMemberBook find)
        {
            var memberId = find.MemberId;
            var context  = new BookishContext();
            var copyList = context.Copies_Book_Member
                           .Where(s => s.MemberId == memberId)
                           .Include(c => c.Book)
                           .Include(m => m.Member)
                           .ToList();

            var list = new MemberBookListViewModel(copyList);

            return(View(list));
        }
예제 #25
0
 public IActionResult BookInsert(Book newbook)
 {
     using (var context = new BookishContext())
     {
         var book = new Book()
         {
             Title  = newbook.Title,
             Author = newbook.Author,
             Year   = newbook.Year
         };
         context.Books.Add(book);
         context.SaveChanges();
     }
     return(RedirectToAction("BookList"));
 }
예제 #26
0
        public IActionResult CopyDelete(String CopyId)
        {
            var copy = new Copy()
            {
                CopyId = Int32.Parse(CopyId)
            };

            using (var context = new BookishContext())
            {
                context.Remove <Copy>(copy);
                context.SaveChanges();
            }

            return(RedirectToAction("CopyAdd"));
        }
예제 #27
0
        public IActionResult AllTheBooks()
        {
            var bookList = new BookListModel {
            };
            // bookList.BookList= new List<BookModel>();

            var context = new BookishContext();
            var shelves = context.BookModel;

            foreach (var book in shelves)
            {
                bookList.BookList.Add(book);
            }

            return(View(bookList));
        }
예제 #28
0
        public IActionResult Edit(Member member)
        {
            using (var LibraryCtx = new BookishContext())
            {
                var    MemberId       = member.MemberId;
                Member memberToUpdate = LibraryCtx.Members.Find(MemberId);
                memberToUpdate.FirstName     = member.FirstName;
                memberToUpdate.Surname       = member.Surname;
                memberToUpdate.Email         = member.Email;
                memberToUpdate.ContactNumber = member.ContactNumber;

                LibraryCtx.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
예제 #29
0
        public IActionResult CopiesList(FindCopy find)
        {
            if (find.Title != null)
            {
                var bookTitle     = find.Title;
                var context       = new BookishContext();
                var availableList = context.Copies_Book_Member
                                    .Where(s => s.Book.Title.Contains(bookTitle))
                                    .Where(s => s.MemberId == null)
                                    .Include(c => c.Book)
                                    .ToList();

                var takenList = context.Copies_Book_Member
                                .Where(s => s.Book.Title.Contains(bookTitle))
                                .Where(s => s.MemberId != null)
                                .Include(c => c.Book)
                                .Include(m => m.Member)
                                .ToList();

                var numofcopies  = availableList.Count + takenList.Count;
                var numAvailable = availableList.Count;
                var list         = new CopyListViewModel(numofcopies, numAvailable, takenList, availableList);
                return(View(list));
            }
            else
            {
                var bookId        = find.BookId;
                var context       = new BookishContext();
                var availableList = context.Copies_Book_Member
                                    .Where(s => s.BookId == bookId)
                                    .Where(s => s.MemberId == null)
                                    .Include(c => c.Book)
                                    .ToList();

                var takenList = context.Copies_Book_Member
                                .Where(s => s.BookId == bookId)
                                .Where(s => s.MemberId != null)
                                .Include(c => c.Book)
                                .Include(m => m.Member)
                                .ToList();

                var numofcopies  = availableList.Count + takenList.Count;
                var numAvailable = availableList.Count;
                var list         = new CopyListViewModel(numofcopies, numAvailable, takenList, availableList);
                return(View(list));
            }
        }
예제 #30
0
        public IActionResult Details(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();

            CopyCatalogueViewModel CopyList = new CopyCatalogueViewModel();

            CopyList.CopyCatalogue = copies.ToList();
            return(View(CopyList));
        }