public void AddNewBookCategory(ActionExecutionContext context, string bookCategoryName)
        {
            if ((context.EventArgs as KeyEventArgs).Key == Key.Return && !String.IsNullOrWhiteSpace(bookCategoryName))
            {
                (context.EventArgs as KeyEventArgs).Handled = true;

                BookCategory bookCat = BookCategories.FirstOrDefault(p => p.Name.ToLower() == bookCategoryName.ToLower());
                if (bookCat != null)
                {
                    SelectedBookCategory = bookCat;
                    return;
                }

                if (MessageBox.Show(String.Format(App.GetString("AreYouSureAddCategory"), bookCategoryName), App.GetString("NewCategory"),
                                    MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                {
                    using (var dbService = _dbServiceManager.GetService())
                    {
                        BookCategory newBookCat = new BookCategory()
                        {
                            Name = bookCategoryName
                        };
                        newBookCat.Id = dbService.BookCategories.Add(newBookCat);

                        BookCategories.Add(newBookCat);
                        SelectedBookCategory = newBookCat;
                    }
                }
                else
                {
                    SelectedBookCategory = null;
                }
            }
        }
Esempio n. 2
0
        public void AddCategory(Category category, bool isPrimary = false)
        {
            if (IsCategoryInList(category))
            {
                throw new BookException("Category already added to this book");
            }

            if (isPrimary && BookCategories.Any(e => e.IsPrimary))
            {
                throw new BookException("Book already contains a primary category, a book can only have a single primary category");
            }

            var bc = new BookCategory(this, category, isPrimary);

            BookCategories.Add(bc);
        }