Example #1
0
        public static void DeleteItem(IBookCatalogItem itemToDelete)
        {
            BookCatalog bookCatalog = new BookCatalog( );

            DeleteItem(bookCatalog, itemToDelete);
            bookCatalog.SubmitChanges( );
        }
Example #2
0
        public void ShowDialog(UIElement parent, ItemType type, IBookCatalogItem dataToEdit, Action <bool> completed)
        {
            BookCatalog    = new BookCatalog( );
            parentDetails  = parent;
            completeAction = completed;

            SetupData(type, dataToEdit);
            parentDetails.IsEnabled = false;
            Visibility = Visibility.Visible;
        }
Example #3
0
        private void SetupData(ItemType type, IBookCatalogItem dataToEdit)
        {
            if (dataToEdit == null)
            {
                dataItem = Catalog.AddNewItem(BookCatalog, type);
            }
            else
            {
                dataItem = Catalog.GetExistingItem(BookCatalog, dataToEdit);
            }

            BindDataToEditForm( );
            LoadAssociatedLists( );
        }
Example #4
0
        public static IBookCatalogItem GetExistingItem(BookCatalog bookCatalog, IBookCatalogItem dataItem)
        {
            if (dataItem is Author)
            {
                return(bookCatalog.Authors.Single(author => author == dataItem as Author));
            }
            if (dataItem is Book)
            {
                return(bookCatalog.Books.Single(book => book == dataItem as Book));
            }
            if (dataItem is Category)
            {
                return(bookCatalog.Categories.Single(category => category == dataItem as Category));
            }

            throw new Exception("Unknown data type");
        }
Example #5
0
        public static void DeleteItem(BookCatalog bookCatalog, IBookCatalogItem itemToDelete)
        {
            if (!itemToDelete.CanDelete( ))
            {
                return;
            }
            IBookCatalogItem dataItem = GetExistingItem(bookCatalog, itemToDelete);

            if (dataItem is Author)
            {
                bookCatalog.Authors.DeleteOnSubmit(dataItem as Author);
            }
            if (dataItem is Book)
            {
                bookCatalog.Books.DeleteOnSubmit(dataItem as Book);
            }
            if (dataItem is Category)
            {
                bookCatalog.Categories.DeleteOnSubmit(dataItem as Category);
            }
        }
Example #6
0
        public static IBookCatalogItem AddNewItem(BookCatalog bookCatalog, ItemType type)
        {
            IBookCatalogItem dataItem = null;

            if (type == ItemType.Author)
            {
                dataItem = new Author( );
                bookCatalog.Authors.InsertOnSubmit(dataItem as Author);
            }

            if (type == ItemType.Book)
            {
                dataItem = new Book( );
                bookCatalog.Books.InsertOnSubmit(dataItem as Book);
            }

            if (type == ItemType.Category)
            {
                dataItem = new Category( );
                bookCatalog.Categories.InsertOnSubmit(dataItem as Category);
            }

            return(dataItem);
        }
Example #7
0
 public static IBookCatalogItem GetExistingItem(IBookCatalogItem dataItem)
 {
     return(GetExistingItem(new BookCatalog( ), dataItem));
 }