Beispiel #1
0
        private void EditSectionBtn_Click(object sender, RoutedEventArgs e)
        {
            SectionViewModel sectionVM = dataGrid.SelectedItem as SectionViewModel;

            AddSection editSection = new AddSection(libraryItems, sectionVM.Name, sectionVM.Description, libraryItems.First(i => i.Id == sectionVM.LibraryId));

            if (editSection.ShowDialog().Value)
            {
                string           name        = editSection.Name.Text;
                string           description = editSection.Description.Text;
                LibraryViewModel model       = editSection.SelectedItem;

                if (sectionVM != null && name != null && model != null)
                {
                    Models.Section section = sectionController.GetById(sectionVM.Id);
                    Library        library = libraryController.GetById(model.Id);
                    section.Name        = sectionVM.Name = name;
                    sectionVM.LibraryId = library.Id;
                    section.Library     = library;
                    section.Description = sectionVM.Description = description;
                    section.ModifiedOn  = sectionVM.ModifiedOn = DateTime.Now;
                    sectionController.Edit(section);
                }
            }
        }
Beispiel #2
0
        private void AddBookBtn_Click(object sender, RoutedEventArgs e)
        {
            InitDataSource(ref bookItems, Mapper.BooksToBookViewModels, bookController.Get);

            AddBook addBook = new AddBook(
                sectionItems   = InitItems(ref sectionItems, Mapper.SectionsToSectionViewModels, sectionController.Get),
                publisherItems = InitItems(ref publisherItems, Mapper.PublishersToPublisherViewModels, publisherController.Get)
                );

            if (addBook.ShowDialog().Value)
            {
                string             name        = addBook.Name.Text;
                string             description = addBook.Description.Text;
                Models.Condition   condition   = (Models.Condition)Enum.Parse(typeof(Models.Condition), addBook.Condition.Text);
                SectionViewModel   sectionVM   = addBook.SelectedSectionItem;
                PublisherViewModel publisherVM = addBook.SelectedPublisherItem;

                if (name != null && sectionVM != null && publisherVM != null)
                {
                    Models.Section section   = sectionController.GetById(sectionVM.Id);
                    Publisher      publisher = publisherController.GetById(publisherVM.Id);
                    Book           book      = new Book(name, description, condition, section, publisher);
                    bookController.Add(book);
                    bookItems.Add(Mapper.BookToBookViewModel(book));
                    return;
                }
            }
        }
Beispiel #3
0
        private void AddSectionBtn_Click(object sender, RoutedEventArgs e)
        {
            InitDataSource(ref sectionItems, Mapper.SectionsToSectionViewModels, sectionController.Get);

            AddSection addSection = new AddSection(libraryItems);

            if (addSection.ShowDialog().Value)
            {
                string           name        = addSection.Name.Text;
                string           description = addSection.Description.Text;
                LibraryViewModel model       = addSection.SelectedItem;

                if (name != null && model != null)
                {
                    Library        library = libraryController.GetById(model.Id);
                    Models.Section section = new Models.Section(name, description, library);
                    sectionController.Add(section);
                    sectionItems.Add(Mapper.SectionToSectionViewModel(section));
                    return;
                }
            }
        }
Beispiel #4
0
        private void EditBookBtn_Click(object sender, RoutedEventArgs e)
        {
            BookViewModel bookVM = dataGrid.SelectedItem as BookViewModel;

            AddBook editBook = new AddBook(
                sectionItems   = InitItems(ref sectionItems, Mapper.SectionsToSectionViewModels, sectionController.Get),
                publisherItems = InitItems(ref publisherItems, Mapper.PublishersToPublisherViewModels, publisherController.Get),
                bookVM.Name,
                bookVM.Description,
                bookVM.Condition,
                sectionItems.First(i => i.Id == bookVM.SectionId), publisherItems.First(i => i.Id == bookVM.PublisherId)
                );

            if (editBook.ShowDialog().Value)
            {
                string             name        = editBook.Name.Text;
                string             description = editBook.Description.Text;
                Models.Condition   condition   = (Models.Condition)Enum.Parse(typeof(Models.Condition), editBook.Condition.Text);
                SectionViewModel   sectionVM   = editBook.SelectedSectionItem;
                PublisherViewModel publisherVM = editBook.SelectedPublisherItem;

                if (bookVM != null && name != null && sectionVM != null && publisherVM != null)
                {
                    Book           book      = bookController.GetById(bookVM.Id);
                    Models.Section section   = sectionController.GetById(sectionVM.Id);
                    Publisher      publisher = publisherController.GetById(publisherVM.Id);
                    book.Name          = bookVM.Name = name;
                    bookVM.SectionId   = section.Id;
                    bookVM.PublisherId = publisher.Id;
                    book.Section       = section;
                    book.Publisher     = publisher;
                    book.Condition     = bookVM.Condition = condition;
                    book.Description   = bookVM.Description = description;
                    book.ModifiedOn    = bookVM.ModifiedOn = DateTime.Now;
                    bookController.Edit(book);
                }
            }
        }