コード例 #1
0
ファイル: Books.cs プロジェクト: Ozerich/labs
        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
ファイル: UserBook.cs プロジェクト: Ozerich/labs
        public static void PutBook(int bookId, int userId)
        {
            Catalog catalog = new Catalog();

            var q = from book in catalog.UserBooks where book.Book_Id == bookId where book.User_Id == userId select book;

            UserBook userBook = q.First();
            catalog.UserBooks.DeleteOnSubmit(userBook);
            catalog.SubmitChanges();
        }
コード例 #3
0
ファイル: Books.cs プロジェクト: Ozerich/labs
        public static void AddCategory(string name)
        {
            Catalog catalog = new Catalog();

            BookCategory cat = new BookCategory();
            cat.Name = name;

            catalog.BookCategories.InsertOnSubmit(cat);
            catalog.SubmitChanges();
        }
コード例 #4
0
ファイル: UserBook.cs プロジェクト: Ozerich/labs
        public static void TakeBook(int bookId, int userId)
        {
            Catalog catalog = new Catalog();

            UserBook userBook = new UserBook();
            userBook.Book_Id = bookId;
            userBook.User_Id = userId;

            catalog.UserBooks.InsertOnSubmit(userBook);
            catalog.SubmitChanges();
        }
コード例 #5
0
ファイル: Users.cs プロジェクト: Ozerich/labs
        public static void CreateUser(string login, string password)
        {
            User user = new User();
            user.Login = login;
            user.Password = password;

            Catalog catalog = new Catalog();

            catalog.Users.InsertOnSubmit(user);

            catalog.SubmitChanges();
        }
コード例 #6
0
ファイル: Books.cs プロジェクト: Ozerich/labs
        public static void DeleteBook(Book book)
        {
            Catalog catalog = new Catalog();

            var tagq = from tag in catalog.Tags where tag.Book_Id == book.Id select tag;
            foreach (BookTag tag in tagq)
                catalog.Tags.DeleteOnSubmit(tag);

            var userq = from t in catalog.UserBooks where t.Book_Id == book.Id select t;
            foreach (UserBook ub in userq)
                catalog.UserBooks.DeleteOnSubmit(ub);

            catalog.SubmitChanges();

            var q = from qBook in catalog.Books where qBook.Id == book.Id select book;

            Book deleteBook = q.First();

            catalog.Books.Attach(deleteBook);
            catalog.Books.DeleteOnSubmit(deleteBook);

            catalog.SubmitChanges();
        }
コード例 #7
0
ファイル: Books.cs プロジェクト: Ozerich/labs
        public static void DeleteCategory(int catId)
        {
            Catalog catalog = new Catalog();

            var bookQuery = from book in catalog.Books where book.parentId == catId select book;
            foreach (Book bookElem in bookQuery)
                DeleteBook(bookElem);

            var categoryQuery = from category in catalog.BookCategories where category.Id == catId select category;

            catalog.BookCategories.DeleteOnSubmit(categoryQuery.First());
            catalog.SubmitChanges();
        }
コード例 #8
0
ファイル: Books.cs プロジェクト: Ozerich/labs
        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();
        }