Esempio n. 1
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"));
        }
Esempio n. 2
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"));
            }
        }
Esempio n. 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"));
        }
Esempio n. 4
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 }));
            }
        }
Esempio n. 5
0
        public IActionResult AddOneBookFormMethod(BookModel book)
        {
            var context = new BookishContext();

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

            return(RedirectToAction(nameof(AddOneBook)));
        }
Esempio n. 6
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)));
        }
Esempio n. 7
0
 public IActionResult AddMember(Member newmember)
 {
     using (var LibraryCtx = new BookishContext())
     {
         LibraryCtx.Members.Add(newmember);
         LibraryCtx.SaveChanges();
     }
     return(RedirectToAction("AddMember"));
 }
Esempio n. 8
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)));
        }
Esempio n. 9
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"));
        }
Esempio n. 10
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"));
        }
Esempio n. 11
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"));
 }
Esempio n. 12
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"));
        }
Esempio n. 13
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"));
        }
Esempio n. 14
0
 public IActionResult MemberInsert(Member newmember)
 {
     // Console.WriteLine (newbook);
     using (var context = new BookishContext())
     {
         // move the values obtained from the form to the variable book
         var member = new Member()
         {
             Name      = newmember.Name,
             ContactNo = newmember.ContactNo,
             Email     = newmember.Email
         };
         context.Members.Add(member);
         context.SaveChanges();
     }
     return(RedirectToAction("MemberList"));
 }
Esempio n. 15
0
        public IActionResult BookCheckoutPost(BookCheckedOutModel item)
        {
            var context = new BookishContext();

            var bookOut = context.BookModel.Find(item.BookId);

            bookOut.BookBorrowedCopies  += 1;
            bookOut.BookAvailableCopies -= 1;

            var userOut = context.UserModel.Find(item.UserId);

            userOut.AmountBorrowedByUser += 1;

            context.BookCheckedOutModel.Add(item);

            context.SaveChanges();

            return(RedirectToAction(nameof(BookCheckout)));
        }
Esempio n. 16
0
        public IActionResult ReturnB(String CopyId, String BookId)
        {
            var copy = new Copy()
            {
                CopyId = Int32.Parse(CopyId), BookId = Int32.Parse(BookId)
            };

            copy.MemberId  = null;
            copy.IssueDate = null;
            copy.DueDate   = null;

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

            return(RedirectToAction("FindCopies"));
        }
Esempio n. 17
0
        public IActionResult Delete(int id)
        {
            var BookId = id;

            using (var LibraryCtx = new BookishContext())
            {
                Book book = LibraryCtx.Books.Find(BookId);
                LibraryCtx.Books.Remove(book);
                List <Copy> copies = LibraryCtx.Copies.Where(b => b.Book == book).ToList();
                LibraryCtx.Copies.RemoveRange(copies);
                foreach (var c in copies)
                {
                    LibraryCtx.Checkouts.RemoveRange(LibraryCtx.Checkouts.Where(x => x.Copy == c).ToList());
                }

                LibraryCtx.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 18
0
        public IActionResult MemberChange(String MemberId, String Name, String ContactNo, String Email)

        {
            var member = new Member()
            {
                MemberId = Int32.Parse(MemberId)
            };

            member.Name      = Name;
            member.ContactNo = ContactNo;
            member.Email     = Email;


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

            return(RedirectToAction("MemberList"));
        }
Esempio n. 19
0
        public IActionResult AddCopy(int id, int NumOfCopies)
        {
            var BookId = id;

            using (var LibraryCtx = new BookishContext())
            {
                Book book = LibraryCtx.Books.Find(BookId);
                if (book == null)
                {
                    return(RedirectToAction("Error"));
                }

                for (var i = 0; i < NumOfCopies; i++)
                {
                    Copy NewCopy = new Copy();
                    NewCopy.Book       = book;
                    NewCopy.CheckedOut = false;
                    LibraryCtx.Copies.Add(NewCopy);
                }

                LibraryCtx.SaveChanges();
            }
            return(RedirectToAction("Details", new { id = BookId }));
        }