Пример #1
0
        public static void AddBook(int catId, string Title, string Genre, string Author, string Publication, int PagesCount, int Year, EnumFileFormat fileFormat, List<string> Tags)
        {
            Book book = new Book();

            book.parentId = catId;
            book.Title = Title;
            book.Author = Author;
            book.parentId = catId;
            book.Publication = Publication;
            book.PagesCount = PagesCount;
            book.Year = Year;
            book.FileFormat = fileFormat;
            book.Genre = Genre;
            book.Tags = Tags;

            Catalog catalog = new Catalog();

            catalog.Books.InsertOnSubmit(book);

            catalog.SubmitChanges();

            int bookId = book.Id;

            foreach (string tag in book.Tags)
            {
                BookTag bookTag = new BookTag();
                bookTag.Name = tag;
                bookTag.Book_Id = bookId;

                catalog.Tags.InsertOnSubmit(bookTag);
            }

            catalog.SubmitChanges();
        }
Пример #2
0
        public static void UpdateBook(int bookId, int catId, string Title, string Genre, string Author, string Publication, int PagesCount, int Year, EnumFileFormat fileFormat, List<string> Tags)
        {
            Catalog catalog = new Catalog();

            var q = from ord in catalog.Books where ord.Id == bookId select ord;

            Book book = q.First();
            book.Title = Title;
            book.Author = Author;
            book.parentId = catId;
            book.Publication = Publication;
            book.PagesCount = PagesCount;
            book.Year = Year;
            book.FileFormat = fileFormat;
            book.Genre = Genre;
            book.Tags = Tags;

            var tagQuery = from tag in catalog.Tags where tag.Book_Id == bookId select tag;
            foreach (BookTag bookTag in tagQuery)
            {

                catalog.Tags.DeleteOnSubmit(bookTag);
            }

            foreach(string tag in book.Tags)
            {
                BookTag bookTag = new BookTag();
                bookTag.Name = tag;
                bookTag.Book_Id = bookId;

                catalog.Tags.InsertOnSubmit(bookTag);
            }

            catalog.SubmitChanges();
        }