Ejemplo n.º 1
0
        /// <summary>
        /// Add new member
        /// </summary>
        /// <param name="name"></param>
        /// <param name="personalNumber"></param>
        public void Add(string name, string personalNumber)
        {
            if (ContainsPersonalNumber(personalNumber))
            {
                throw new ValidationException("The personal number you are trying to add already exists");
            }

            Member member = new Member()
            {
                Name = name,
                PersonalNumber = personalNumber
            };

            ValidationResult error = ObjectValidator.Validate(member);

            if (error != null)
            {
                throw new ValidationException(error.ErrorMessage);
            }
            else
            {
                _memberRepository.Add(member);
                OnUpdated(new EventArgs());
            }
        }
Ejemplo n.º 2
0
        /// <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());
            }
        }
Ejemplo n.º 3
0
 public Loan(string timeOfLoan, string dueDate, Book _book, Member _member)
 {
     this.LoanId = generateNewId();
     this.TimeOfLoan = timeOfLoan;
     this.DueDate = dueDate;
     this.book = _book;
     this.member = _member;
     this.TimeOfRetrun = "";
 }
Ejemplo n.º 4
0
 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--;
 }
Ejemplo n.º 5
0
        public ActionResult Check(string drop, Library.Models.Admin admin, Library.Models.Member member)
        {
            if (drop == "1")
            {
                using (LibraryDbEntities db = new LibraryDbEntities())
                {
                    var userDetatils = db.Admins.Where(x => x.user_name == admin.user_name && x.password == admin.password).FirstOrDefault();
                    if (userDetatils != null)
                    {
                        Session["UserId"] = userDetatils.user_id;
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (userDetatils == null)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            else
            {
                using (LibraryDbEntities db = new LibraryDbEntities())
                {
                    var userDetatils = db.Members.Where(x => x.user_name == member.user_name && x.password == member.password).FirstOrDefault();
                    if (userDetatils != null)
                    {
                        Session["UserId"] = userDetatils.user_id;
                        return(RedirectToAction("Index", "Home"));
                    }
                    if (userDetatils == null)
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }

            return(View());
        }
Ejemplo n.º 6
0
 public void Remove(Member item)
 {
 }
Ejemplo n.º 7
0
 public void Edit(Member item)
 {
 }
Ejemplo n.º 8
0
 public void Add(Member item)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Set the predetermined value on member 
 /// </summary>
 /// <param name="member"></param>
 private void SetSelectedMember(Member member)
 {
     if (member != null)
     {
         cbx_Members.SelectedItem = member;
     }
 }
Ejemplo n.º 10
0
        /// <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;
                    }
            }
        }
Ejemplo n.º 11
0
 private void SetSelectedMember(Member member)
 {
     foreach (DataGridViewRow row in grd_Members.Rows)
     {
         if ((int)row.Cells[0].Value == member.Id)
         {
             row.Selected = true;
             break;
         }
     }
 }
Ejemplo n.º 12
0
        private void grd_Members_SelectionChanged(object sender, EventArgs e)
        {
            if (grd_Members.SelectedRows.Count > 0)
            {
                _selectedMember = GetSelectedMember();

                lbl_MemberName.Text = _selectedMember.Name;
                lbl_MemberID.Text = _selectedMember.Id.ToString();
                lbl_pNr.Text = _selectedMember.PersonalNumber;

                UpdateMemberLoans(_loanService.Search(_selectedMember, cbx_Members_ShowReturnedLoans.Checked));

                pnl_SelectedMember.Visible = true;
            }
            else
            {
                _selectedMember = null;
                pnl_SelectedMember.Visible = false;
            }

            txt_MemberSearch.Focus();
        }
Ejemplo n.º 13
0
 public void Add(Member item)
 {
     _memberRepository.Add(item);
     OnUpdated(this, new EventArgs());
 }
Ejemplo n.º 14
0
        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();
        }
Ejemplo n.º 15
0
 public NewLoanForm(BookService bookService, BookCopyService bookCopyService, MemberService memberService, LoanService loanService, Member selectedMember)
     : this(bookService, bookCopyService, memberService, loanService)
 {
     SetSelectedMember(selectedMember);
 }
Ejemplo n.º 16
0
        private void addMemberBtn_Click(object sender, EventArgs e)
        {
            if (!mainPanel.Visible)
            {
                string name = memberNameTb.Text;
                int pNumber = int.Parse(pNumberTb.Text);

                Member _member = new Member(pNumber, name);

                _memberService.Add(_member);
                pNumberTb.Text = "";
                memberNameTb.Text = "";
            }
        }
Ejemplo n.º 17
0
        public void CreateLibrary()
        {
            Author AlexDumas = new Author()
            {
                Name = "Alexander Dumas",
                books = new List<Book>()
            };

            Author JamesJoyce = new Author()
            {
                Name = "James Joyce",
                books = new List<Book>()
            };

            string description = "The story of Edmund Dantes, self-styled Count of Monte Cristo, is told with consummate skill.";
            string descriptionTwo = "This is a description";
            string descriptionThree = "It was the best of times, it was the worst of times";

            string title = "The Count of Monte Cristo";
            string titleTwo = "The Count of Monte Blisto";
            string titleThree = "Ulysses";

            long isbnOne = 9781435132115;
            long isbnTwo = 9781435132114;
            long isbnThree = 9789100146238;

            int nrOfCopyOne = 7;
            int nrOfCopyTwo = 6;

            Book monteCristo = new Book(AlexDumas, title, description, isbnOne, nrOfCopyOne);
            Book monteBlisto = new Book(AlexDumas, titleTwo, descriptionTwo, isbnTwo, nrOfCopyTwo);
            Book ulysses = new Book(JamesJoyce, titleThree, descriptionThree, isbnThree, nrOfCopyOne);

            AlexDumas.books.Add(monteCristo);
            AlexDumas.books.Add(monteBlisto);
            JamesJoyce.books.Add(ulysses);

            _authorService.Add(AlexDumas);
            _authorService.Add(JamesJoyce);
            //_bookService.Add(monteCristo);

            Member Love = new Member()
            {
                Pnumber = 920217,
                Name = "Love",
                loans = new List<Loan>()
            };

            _memberService.Add(Love);

            BookCopy bCopy = _bookCopyService.Find(monteCristo.Id);

            Loan loanTest = new Loan(bCopy, Love);
            _loanService.Add(loanTest);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Find all loans or loans by member
        /// </summary>
        /// <param name="member">Member to show loans for, null means all members</param>
        /// <param name="showReturnedLoans">Include returned loans</param>
        /// <returns></returns>
        public IEnumerable<Loan> Search(Member member, bool showReturnedLoans)
        {
            var loans = _loanRepository.All();

            if (member != null)
                loans = loans.Where(l => l.Member.Id == member.Id);

            if (!showReturnedLoans)
                loans = loans.Where(l => l.TimeOfReturn == null);

            return loans;
        }