예제 #1
0
 private void Grid_Loaded(object sender, RoutedEventArgs args)
 {
     titleTextBox.Text            = Book.Title;
     ratingTextBox.Text           = Book.Rating.ToString();
     descriptionTextBox.Text      = Book.Description;
     sectionComboBox.SelectedItem = (ComboBoxItem)this.FindName(Book.Section.ToString());
     countTextBox.Text            = BookCounter.Count(Book.Id).ToString();
     bookAuthors.ItemsSource      = Book.Authors;
 }
예제 #2
0
 public BookDto ConvertBook(Book book)
 {
     return(new BookDto()
     {
         Id = book.Id,
         Title = book.Title,
         Rating = book.Rating,
         Quantity = BookCounter.Count(book.Id),
         Section = book.Section.ToString().ToLower().Replace("_", " "),
         Shelf = BookArranger.GetShelf(book.Id)
     });
 }
예제 #3
0
        private void Save_Button_Click(object sender, RoutedEventArgs e)
        {
            if (!float.TryParse(ratingTextBox.Text, out float rating))
            {
                MessageBox.Show("The value of rating is invalid. Enter it again");
                return;
            }

            if (!int.TryParse(countTextBox.Text, out int count))
            {
                MessageBox.Show("The value of count is invalid. Enter it again");
                return;
            }

            if (!int.TryParse(shelfTextBox.Text, out int shelf))
            {
                MessageBox.Show("The value of shelf is invalid. Enter it again");
                return;
            }

            Book.Title       = titleTextBox.Text;
            Book.Rating      = rating;
            Book.Description = descriptionTextBox.Text;
            Book.Section     = BookUtils.ParseSection(sectionComboBox.Text);
            Book.Authors     = (bookAuthors.ItemsSource as IList <Author>);

            BookService.SaveOrUpdate(Book);

            if (!BookCounter.IsPresent(Book.Id))
            {
                BookCounter.AddNew(Book.Id, count);
            }
            else
            {
                BookCounter.SetCount(Book.Id, count);
            }

            if (!BookArranger.IsPresent(Book.Id))
            {
                BookArranger.AddEntry(Book.Id, shelf);
            }
            else
            {
                BookArranger.Set(Book.Id, shelf);
            }

            // if book is saved
            // it will be displayed onto main datagrid
            BookIsSaved = true;
            MessageBox.Show("Done");
        }