Exemplo n.º 1
0
 public static bool ValidateReturning(IUserModel reader, IBookModel book)
 {
     if (reader != null && reader.TakenBooks.Contains(book.ID) && book?.ReaderID == reader.ID)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
 public static bool  ValidateIssuing(IUserModel reader, IBookModel book)
 {
     if (book?.Status == Status.Available && reader?.TakenBooks.Count < maxBookAmount)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
0
        // GET: Books/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            IBookModel bookModel = this.bookService.FindById(id);

            if (bookModel == null)
            {
                return(HttpNotFound());
            }
            return(View(bookModel));
        }
Exemplo n.º 4
0
        public void AddBook(IBookModel book, bool newBook)
        {
            if (!this.books.Contains(book))
            {
                books.Add(book);

                if (newBook)
                {
                    NewBook = book;
                }

                this.SortBooks();
            }
        }
Exemplo n.º 5
0
        public IBookModel FindById(Guid?id)
        {
            IBookModel result = null;

            if (id.HasValue)
            {
                Book bookElement = this.bookSetWrapper.GetById(id.Value);
                if (bookElement != null)
                {
                    result = new BookModel(bookElement);
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Check all field is not null or empty of some another validation rules
        /// </summary>
        public void Validate()
        {
            IBookModel ibook = this;

            if (string.IsNullOrEmpty(ibook.Author))
            {
                new BookException("Author is null or empty");
            }

            if (string.IsNullOrEmpty(ibook.Name))
            {
                new BookException("Name is null or empty");
            }

            IDeliveryModel idel = this;

            if (string.IsNullOrEmpty(idel.Address))
            {
                new BookException("Address is null or empty");
            }
        }
Exemplo n.º 7
0
        private void OnSaveBook(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(titleBox.Text) && !string.IsNullOrWhiteSpace(isbnBox.Text) &&
                !string.IsNullOrWhiteSpace(publisherBox.Text) && !string.IsNullOrWhiteSpace(authorListBox.Text) &&
                !string.IsNullOrWhiteSpace(genreBox.Text) && !string.IsNullOrWhiteSpace(qtyBox.Text))
            {
                BookGenre  genres  = new BookGenre();
                List <int> authors = new List <int>();
                int.TryParse(qtyBox.Text, out int qty);

                foreach (var genre in genreBox.CheckedItems)
                {
                    genres = genres | (BookGenre)Enum.Parse(typeof(BookGenre), genre.ToString());
                }

                foreach (Author author in authorListBox.SelectedItems)
                {
                    authors.Add(author.ID);
                }

                for (int i = 0; i < qty; i++)
                {
                    Book = new Book(title: titleBox.Text, isbn: isbnBox.Text, authorID: authors,
                                    publisher: publisherBox.Text, genre: genres, description: descriptionBox.Text);

                    NewBook?.Invoke(this, new BookRelatedEventArgs {
                        Book = Book
                    });
                }
                MessageBox.Show(StringConstants.BookRegistered(titleBox.Text, isbnBox.Text));
                RefreshAndClear();
            }
            else
            {
                MessageBox.Show(StringConstants.missingInfo);
            }
            AutomaticFormPosition.SaveFormStatus(this);
        }
Exemplo n.º 8
0
 public void ReturnBook(IBookModel book)
 {
     TakenBooks.Remove(book.ID);
     History.Add(new ReadingHistory(book.ID, book.IssueDate, book.ReturnDate));
 }
Exemplo n.º 9
0
 public void TakeBook(IBookModel book)
 {
     TakenBooks.Add(book.ID);
 }
Exemplo n.º 10
0
 public void RemoveBook(IBookModel book)
 {
     //TODO logic for taken books here or in the book class
     Books.Remove(book);
     SerializeBooks();
 }
Exemplo n.º 11
0
 public void AddBook(IBookModel book)
 {
     Books.Add(book);
     SerializeBooks();
 }
Exemplo n.º 12
0
 public AuthorController(IAuthorModel authorModel, IBookModel bookModel)
 {
     _authorModel = authorModel;
     _bookModel   = bookModel;
 }
Exemplo n.º 13
0
 public static void ReturnBook(IUserModel reader, IBookModel book)
 {
     book.Return();
     reader.ReturnBook(book);
     LibraryDataIO.Instance.SerializeAllData();
 }
Exemplo n.º 14
0
 public static void IssueBookToReader(IUserModel reader, IBookModel book)
 {
     book.Issue(reader);
     reader.TakeBook(book);
     LibraryDataIO.Instance.SerializeAllData();
 }
Exemplo n.º 15
0
 private void AddNewBook(object sender, BookRelatedEventArgs e)
 {
     Book = e.Book;
     LibraryDataIO.Instance.AddBook(Book);
     var barcode = barcodeGenerator.GenerateBarcode(Book.ID);
 }
Exemplo n.º 16
0
 public BookController(IBookModel model)
 {
     _model = model;
 }