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")); } }
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 })); } }
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")); }
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")); }
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"); }
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)); }
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)); }
public IActionResult AddMember(Member newmember) { using (var LibraryCtx = new BookishContext()) { LibraryCtx.Members.Add(newmember); LibraryCtx.SaveChanges(); } return(RedirectToAction("AddMember")); }
public IActionResult AddOneBookFormMethod(BookModel book) { var context = new BookishContext(); context.BookModel.Add(book); context.SaveChanges(); return(RedirectToAction(nameof(AddOneBook))); }
[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))); }
public IActionResult MemberList() { var context = new BookishContext(); var memberlist = context.Members .ToList(); var list = new MemberListViewModel(memberlist); return(View(list)); }
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)); }
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)); } }
public IActionResult Index() { MemberCatalogueViewModel MemberList = new MemberCatalogueViewModel(); using (var LibraryCtx = new BookishContext()) { MemberList.MemberCatalogue = LibraryCtx.Members.Take(10).ToList(); } return(View(MemberList)); }
public IActionResult BookList() { var context = new BookishContext(); var booklist = context.Books .OrderBy(x => x.Title) .ToList(); var list = new BookListViewModel(booklist); return(View(list)); }
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)); }
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)); }
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)); }
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))); }
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)); }
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)); }
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")); }
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")); }
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)); }
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")); }
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")); }
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)); }
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")); }
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)); } }
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)); }