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(); }
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(); }
public static void AddCategory(string name) { Catalog catalog = new Catalog(); BookCategory cat = new BookCategory(); cat.Name = name; catalog.BookCategories.InsertOnSubmit(cat); catalog.SubmitChanges(); }
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(); }
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(); }
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(); }
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(); }
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(); }