/// <summary> /// Add new loan /// </summary> /// <param name="member"></param> /// <param name="bookCopy"></param> /// <param name="AlreadyExpiredLoan">Register as already expired loan for testing purposes</param> public void Add(Member member, BookCopy bookCopy, bool alreadyExpiredLoan) { if (bookCopy != null && bookCopy.CurrentLoan != null) { throw new ValidationException("This book copy is already on loan"); } Loan loan = new Loan() { TimeOfLoan = DateTime.Now, DueDate = alreadyExpiredLoan ? DateTime.Now.AddDays(-15) : DateTime.Now.AddDays(15), Member = member, BookCopy = bookCopy }; ValidationResult error = ObjectValidator.Validate(loan); if (error != null) { throw new ValidationException(error.ErrorMessage); } else { _loanRepository.Add(loan); OnUpdated(new EventArgs()); } }
/// <summary> /// Constructor /// </summary> /// <param name="timeOfLoan">The date the loan was created</param> /// <param name="bookCopy">One specifik bookcopy</param> /// <param name="member">The member of the loan</param> public Loan(DateTime timeOfLoan, BookCopy bookCopy, Member member) { this.TimeOfLoan = timeOfLoan; this.DueDate = timeOfLoan.AddDays(15); this.BookCopy = bookCopy; this.Member = member; }
/// <summary> /// Construct sets the Loan properties. /// </summary> /// <param name="timeofloan"></param> /// <param name="duedate"></param> /// <param name="bookcopy"></param> /// <param name="member"></param> public Loan(DateTime timeofloan, DateTime duedate, BookCopy bookcopy, Member member) { this.TimeOfLoan = timeofloan; this.DueDate = duedate; this.BookCopy = bookcopy; this.Member = member; this.TimeOfReturn = null; }
public Loan(BookCopy bookCopy, Member member, DateTime startloantime) { this.bookCopy = bookCopy; this.member = member; StartLoanTimestamp = startloantime; DueDate = StartLoanTimestamp.AddDays(15); //ReturnLoanTimestamp = returnLoan; }
public Loan(BookCopy book, Member member, bool loanBool) { TheBook = book; TheMember = member; OnLoan = loanBool; DueDate = new DateTime(); TimeOfLoan = new DateTime(); TimeOfReturn = new DateTime(); }
public Loan(BookCopy _bookCopy, Member _member) { this.member = _member; this.bookCopy = _bookCopy; this.TimeOfLoan = DateTime.Now; this.DueDate = DateTime.Now.AddDays(15); bookCopy.IsLoaned = true; _bookCopy.book.NrOfCopies--; }
public void DoSpecLoan(BookCopy copy, Member person) { time = DateTime.Today; dueDate = DateTime.Today.AddDays(15); bookCopy = copy; bookCopy.Loan = true; member = person; returnTime = DateTime.MaxValue; Loaned = true; }
/// <summary> /// Add new book copy /// </summary> /// <param name="book"></param> public void Add(Book book) { BookCopy bookCopy = new BookCopy() { Book = book }; _bookCopyRepository.Add(bookCopy); OnUpdated(new EventArgs()); }
protected override void Seed(LibraryContext context) { base.Seed(context); //Create test author /*object*/ Author lindaP = new Author() { Name = "Linda Petersson" }; //Create test book /*object*/ Book luluandDumpling = new Book() { ISBN = "123", Title = "The Adventures of Lulu and Dumpling", Description = "A book about two friends.", Author = lindaP }; BookCopy copy1 = new BookCopy() { Book = luluandDumpling, Condition = 10 }; Member viggoLundin = new Member() { PersonalId = "1996", Name = "Viggo Lundin", DateOfMembership = new DateTime(2019, 10, 23) }; Loan loan1 = new Loan() { TimeOfLoan = new DateTime(2019, 10, 24), Member = viggoLundin, BookCopy = copy1 }; //Add test objects to the DbSet. context.Authors.Add(lindaP); context.Books.Add(luluandDumpling); context.BookCopies.Add(copy1); context.Members.Add(viggoLundin); //context.Loans.Add(loan1); //Persist changes to the database context.SaveChanges(); }
public Loan(BookCopy _BookCopy, Member _Member, DateTime?_DateOfLoan = null, DateTime?_DateOfReturn = null) { if (_DateOfLoan != null) { DateOfLoan = _DateOfLoan; } else { DateOfLoan = DateTime.Now; } if (_DateOfReturn != null) { DateOfReturn = _DateOfReturn; } BookCopy = _BookCopy; Member = _Member; OverdueDayPrice = 10; LoanTime = 15; DueDate = DateOfLoan.Value.AddDays(LoanTime); }
public void Add(BookCopy item) { _bookCopyRepository.Add(item); }
/// <summary> /// Event method for the submitbutton in the add/remove section /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void submitButton_Click(object sender, EventArgs e) { switch ((addRemoveEnum)cbbxAction.SelectedIndex) { case addRemoveEnum.AddBook://add book { //txtbxInput1 = title //txtbxInput2 = authorname //txtbxInput3 = ISBN //txtbxInput4 = description Author theAuthor; Book theBook; try { if (txtbxInput1.Text.Length == 0 || txtbxInput2.Text.Length == 0 || txtbxInput3.Text.Length == 0 || txtbxInput4.Text.Length == 0) { throw new InvalidInputException(); } if (authorService.All().Where(a => a.Name == txtbxInput2.Text).Count() == 0) { theAuthor = new Author { Name = txtbxInput2.Text, Books = new List<Book>() }; authorService.Add(theAuthor); } else { theAuthor = authorService.All().Where(A => A.Name == txtbxInput2.Text).First(); } theBook = new Book { Title = txtbxInput1.Text, Author = theAuthor, Copies = new List<BookCopy>(), Description = txtbxInput4.Text, Isbn = txtbxInput3.Text }; bookService.Add(theBook); } catch (InvalidInputException) { MessageBox.Show("Some input was invalid, please controll that none of the input textboxes are empty"); } break; } case addRemoveEnum.AddAuthor: //Add Author { Author theAuthor; //txtbxInput1 = authorname try { if (txtbxInput1.Text.Length == 0) { throw new InvalidInputException(); } theAuthor = new Author { Name = txtbxInput1.Text, Books = new List<Book>() }; authorService.Add(theAuthor); } catch (InvalidInputException) { MessageBox.Show("An author needs to have a name, please input a name in the name textbok"); txtbxInput1.Select(); } break; } case addRemoveEnum.AddBookCopy: //Add book copy { //txtbxInput1 = bookname BookCopy theBookCopy; Book theBook; try { if (txtbxInput1.Text.Length == 0) { throw new InvalidInputException(); } theBook = bookService.All().Where(B => B.Title == txtbxInput1.Text).First(); theBookCopy = new BookCopy { Book = theBook, IsLoaned = false, Condition = "New" }; bookCopyService.Add(theBookCopy); theBook.Copies.Add(theBookCopy); } catch (InvalidInputException) { MessageBox.Show("Please specify wich book you would like to add a copy of in the booktitle textbox"); } catch (InvalidOperationException) { MessageBox.Show("The book was not found, please make sure that the book exists before creating a copy of it"); } break; } case addRemoveEnum.RemoveBook: //RemoveBook { //txtbxInput1 = bookname Book theBook; try { if (txtbxInput1.Text.Length == 0) { throw new InvalidInputException(); } theBook = bookService.All().Where(B => B.Title == txtbxInput1.Text).First(); foreach (var copy in bookCopyService.All().Where(b => b.Book == theBook)) { //remove every copy of the book from bookcopyrepo bookCopyService.Remove(copy); } //Remove the book from bookrepo bookService.Remove(theBook); } catch (InvalidInputException) { MessageBox.Show("Please specify wich book yo would like to remove in the booktitle textbox"); txtbxInput1.Select(); } catch (InvalidOperationException) { MessageBox.Show("The book was not found, please controll that the book exists and that you've entered the correct title"); txtbxInput1.Select(); } break; } case addRemoveEnum.RemoveAuthor: //Remove author { //txtbxInput1 = authorname Author theAuthor; try { if (txtbxInput1.Text.Length == 0) { throw new InvalidInputException(); } //feth author theAuthor = authorService.All().Where(a => a.Name == txtbxInput1.Text).First(); //remove all bookcopies of books written by the author foreach(BookCopy bc in bookCopyService.All().Where(b => b.Book.Author == theAuthor)) { bookCopyService.Remove(bc); } //remove all books written by the author foreach (Book b in bookService.All().Where(b => b.Author == theAuthor)) { bookService.Remove(b); } //finally remove the author authorService.Remove(theAuthor); } catch (NotImplementedException) { MessageBox.Show("Not yet implemented, not a requirement for the project"); } catch (InvalidInputException) { MessageBox.Show("Please input a Author Name in the author name input box"); txtbxInput1.Select(); } catch (InvalidOperationException) { MessageBox.Show("The Author was not found, please make sure that the author exists and you've entered the correct name"); txtbxInput1.Select(); } break; } case addRemoveEnum.RemoveBookCopy: //remove book copy { //txtbxInput1 = bookcopyid BookCopy theBookCopy; int bookCopyId = Convert.ToInt16(txtbxInput1.Text); try { if (txtbxInput1.Text.Length == 0) { throw new InvalidInputException(); } theBookCopy = bookCopyService.All().Where(bc => bc.Id == bookCopyId).First(); bookCopyService.Remove(theBookCopy); } catch (FormatException) { MessageBox.Show("Please make sure that the input in the ID textbox is only numbers"); txtbxInput1.Select(); } catch (InvalidOperationException) { MessageBox.Show("The copy was not found, please make sure that you've entered the right ID and that the copy exists"); } break; } case addRemoveEnum.AddMember: //add member { //txtbxInput1 = name //mtxtbxSSNRadd = socialssnr Member newMember; try { iscorrectofrmat(mtxtbxSSNRadd); } catch (InvalidSSNRException) { MessageBox.Show(mtxtbxSSNRadd.Text + " is not a valid Social security number, please enter a social scurity number by the form YYMMDD-XXXX"); } try { if (txtbxInput1.Text.Length == 0) { throw new InvalidInputException(); } //create new member newMember = new Member { SocialSecurityNr = mtxtbxSSNRadd.Text, Name = txtbxInput1.Text }; memberService.Add(newMember); } catch (InvalidInputException) { MessageBox.Show("A member can't be created without a full name, please enter [name1 name2] in the name textbox"); txtbxInput1.Focus(); } break; } default: { break; } } }
private void grd_BookCopies_SelectionChanged(object sender, EventArgs e) { // Enable/disable buttons depending on selected row if (grd_BookCopies.SelectedRows.Count > 0) { _selectedBookCopy = GetSelectedBookCopy(); // Book on loan if (_selectedBookCopy != null && _selectedBookCopy.CurrentLoan != null) { btn_Books_MakeLoan.Enabled = false; btn_Books_ReturnLoan.Enabled = true; } // Book available else if (_selectedBookCopy != null) { btn_Books_MakeLoan.Enabled = true; btn_Books_ReturnLoan.Enabled = false; } // No book else { btn_Books_MakeLoan.Enabled = false; btn_Books_ReturnLoan.Enabled = false; } } else { _selectedBookCopy = null; btn_Books_MakeLoan.Enabled = false; btn_Books_ReturnLoan.Enabled = false; } }
public void Remove(BookCopy item) { }
public void Edit(BookCopy item) { }
public void Add(BookCopy item) { }
protected override void Seed(LibraryContext context) { base.Seed(context); // Add authors to database. Author jkAuthor = new Author("J.K.", "Rowling"); context.Authors.Add(jkAuthor); Author jrrAuthor = new Author("J.R.R.", "Tolkien"); context.Authors.Add(jrrAuthor); Author ernestAuthor = new Author("Ernest", "Hemingway"); context.Authors.Add(ernestAuthor); Author janeAuthor = new Author("Jane", "Austen"); context.Authors.Add(janeAuthor); Author charlesAuthor = new Author("Charles", "Dickens"); context.Authors.Add(charlesAuthor); //Add books to database. List <Book> booksInDB = new List <Book>(); Book harryP1 = new Book("0-7475-3269-9", "Harry Potter and the Philosopher's Stone", new List <Author>() { jkAuthor }, 1997, "Good book! :)"); context.Books.Add(harryP1); booksInDB.Add(harryP1); Book harryP2 = new Book("0-7475-3849-2", "Harry Potter and the Chamber of Secrets", new List <Author>() { jkAuthor }, 1998, "Good book! :)"); context.Books.Add(harryP2); booksInDB.Add(harryP2); Book harryP3 = new Book("0-7475-4215-5", "Harry Potter and the Prisoner of Azkaban", new List <Author>() { jkAuthor }, 1999, "Good book! :)"); context.Books.Add(harryP3); booksInDB.Add(harryP3); Book harryP4 = new Book("0-7475-4624-X", "Harry Potter and the Goblet of Fire", new List <Author>() { jkAuthor }, 2000, "Good book! :)"); context.Books.Add(harryP4); booksInDB.Add(harryP4); Book harryP5 = new Book("0-7475-5100-6", "Harry Potter and the Order of the Phoenix", new List <Author>() { jkAuthor }, 2003, "Good book! :)"); context.Books.Add(harryP5); booksInDB.Add(harryP5); Book harryP6 = new Book("0-7475-8108-8", "Harry Potter and the Half Blood Prince", new List <Author>() { jkAuthor }, 2005, "Good book! :)"); context.Books.Add(harryP6); booksInDB.Add(harryP6); Book harryP7 = new Book("0-545-01022-5", "Harry Potter and the Deathly Hallows", new List <Author>() { jkAuthor }, 2007, "Good book! :)"); context.Books.Add(harryP7); booksInDB.Add(harryP7); Book sagan1 = new Book("0544003411", "The Lord of the Rings", new List <Author>() { jrrAuthor }, 1954, "Best book! :)"); context.Books.Add(sagan1); booksInDB.Add(sagan1); Book sagan2 = new Book("0007522916", "The Two Towers", new List <Author>() { jrrAuthor }, 1954, "Better book! :)"); context.Books.Add(sagan2); booksInDB.Add(sagan2); //Add members to database. Member linus = new Member("930126-0001", "Limpanxd", "Linus", "Huzell", new DateTime(1993, 1, 26)); context.Members.Add(linus); Member philip = new Member("950724-0002", "Phille", "Philip", "Öhlund", new DateTime(1995, 7, 24)); context.Members.Add(philip); Member martin = new Member("920314-0003", "Styrbjorn", "Martin", "Stenberg", new DateTime(2018, 10, 25)); context.Members.Add(martin); Member per = new Member("890906-0004", "Perka", "Per", "Jernlund", new DateTime(2018, 10, 25)); context.Members.Add(per); Member anton = new Member("930807-0005", "Anton1337", "Anton", "Backe", null); context.Members.Add(anton); Member gorkem = new Member("860101-0006", "GorkemUberHaxx", "Görkem", "Paçaci", null); context.Members.Add(gorkem); //Add book copies to database. foreach (Book book in booksInDB) { for (int i = 0; i < 2; i++) { context.BookCopies.Add(new BookCopy(book)); } } BookCopy hp1 = new BookCopy(harryP1); context.BookCopies.Add(hp1); BookCopy hp2 = new BookCopy(harryP2); context.BookCopies.Add(hp2); BookCopy hp3 = new BookCopy(harryP3); context.BookCopies.Add(hp3); BookCopy hp4 = new BookCopy(harryP4); context.BookCopies.Add(hp4); BookCopy hp5 = new BookCopy(harryP5); context.BookCopies.Add(hp5); BookCopy hp6 = new BookCopy(harryP6); context.BookCopies.Add(hp6); BookCopy hp7 = new BookCopy(harryP7); context.BookCopies.Add(hp7); DateTime Date1 = new DateTime(2004, 10, 22); //Add loans to database. Loan lhp1 = new Loan(hp1, linus); context.Loans.Add(lhp1); context.Loans.Add(new Loan(hp2, linus, new DateTime(2004, 10, 22), new DateTime(2004, 10, 28))); context.Loans.Add(new Loan(hp3, linus, new DateTime(2018, 10, 25))); context.Loans.Add(new Loan(hp4, linus, new DateTime(2017, 11, 1), new DateTime(2017, 11, 27))); context.Loans.Add(new Loan(hp5, linus, new DateTime(2018, 10, 12))); context.Loans.Add(new Loan(hp6, philip)); context.Loans.Add(new Loan(hp7, philip)); // Persist changes to the database. context.SaveChanges(); }
/// <summary> /// Different ways to enter the NewLoanForm, either from the Member view, with the member as predetermined value or /// with the selected book and bookcopy as predetermined values, from the Books view. /// </summary> public NewLoanForm(BookService bookService, BookCopyService bookCopyService, MemberService memberService, LoanService loanService, BookCopy selectedBookCopy) : this(bookService, bookCopyService, memberService, loanService) { SetSelectedBookAndCopy(selectedBookCopy); }
/// <summary> /// Set the predetermined values on book and bookcopy /// </summary> /// <param name="bookCopy"></param> private void SetSelectedBookAndCopy(BookCopy bookCopy) { if (bookCopy != null) { cbx_Books.SelectedItem = bookCopy.Book; cbx_BookCopies.SelectedItem = bookCopy; } }
public Loan(BookCopy copy, Member member) { this.DoSpecLoan(copy, member); }
protected override void Seed(LibraryContext context) { base.Seed(context); Author author1 = new Author() { Name = "Kristina Ohlsson", }; context.Authors.Add(author1); context.SaveChanges(); Author author2 = new Author() { Name = "Jonas Moström", }; context.Authors.Add(author2); context.SaveChanges(); Book book1 = new Book() { Title = "Henrys Hemlighet", ISBN = "9789164206138", Author = author1, }; // Add the book to the DbSet of books. context.Books.Add(book1); // Persist changes to the database context.SaveChanges(); Book book2 = new Book() { Title = "Varulvens Hemlighet", ISBN = "9789188279477", Author = author1, }; context.Books.Add(book2); context.SaveChanges(); BookCopy bookcopy1 = new BookCopy() { Condition = 1, Book = book1 }; BookCopy bookcopy2 = new BookCopy() { Condition = 10, Book = book1 }; BookCopy bookcopy3 = new BookCopy() { Condition = 8, Book = book2 }; context.BookCopies.Add(bookcopy1); context.SaveChanges(); context.BookCopies.Add(bookcopy2); context.SaveChanges(); context.BookCopies.Add(bookcopy3); context.SaveChanges(); Member member1 = new Member() { Name = "Elin Svantesson", PersonalIdentityNumber = "9602253743", MembershipDate = DateTime.Now.AddDays(-12).Date }; context.Members.Add(member1); context.SaveChanges(); Member member2 = new Member() { Name = "Lisa Svantesson", PersonalIdentityNumber = "9804240028", MembershipDate = DateTime.Now.AddDays(-150).Date }; context.Members.Add(member2); context.SaveChanges(); Loan loan1 = new Loan() { TimeOfLoan = DateTime.Today, DueDate = DateTime.Today.AddDays(15), BookCopy = bookcopy1, Member = member1 }; context.Loans.Add(loan1); context.SaveChanges(); Loan loan2 = new Loan() { TimeOfLoan = DateTime.Today.AddDays(-16), DueDate = DateTime.Today.AddDays(-1), BookCopy = bookcopy3, Member = member2 }; context.Loans.Add(loan2); context.SaveChanges(); }