public static bool DeleteAllCategoryAndAuthor(int ID) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { Book_Author book_author = context.Book_Author.FirstOrDefault(t => t.book_ID == ID); while (book_author != null) { context.Book_Author.Remove(book_author); context.SaveChanges(); book_author = context.Book_Author.FirstOrDefault(t => t.book_ID == ID); } Book_Category book_category = context.Book_Category.FirstOrDefault(t => t.book_ID == ID); while (book_category != null) { context.Book_Category.Remove(book_category); context.SaveChanges(); book_category = context.Book_Category.FirstOrDefault(t => t.book_ID == ID); } if (book_author == null && book_category == null) { return(true); } return(false); } } catch (Exception ex) { LogService.log("BOOK", ex.StackTrace); return(false); } }
public static BookData GetBookDataById(int id) { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { Book book = context.Books.FirstOrDefault(b => b.ID == id); if (book != null) { BookData result = ConvertBookToBookData(book); return(result); } } return(null); }
public static bool UpDateBook(BookData b) { try { DeleteAllCategoryAndAuthor(b.ID); Console.WriteLine("ok go here"); using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { Book book = context.Books.FirstOrDefault(bo => bo.ID == b.ID); if (book != null) { book.ISBN = b.ISBN; book.name = b.Name; book.price = b.Price; book.quantity = b.Quantity; book.status = b.Status; book.year = b.Year; book.publisher_ID = b.Publisher_ID; book.description = b.Description; for (int i = 0; i < b.Author.Count; i++) { int ID = b.Author[i].ID; Author author = context.Authors.FirstOrDefault(a => a.ID == ID); Book_Author BA = new Book_Author(); BA.Author = author; BA.Book = book; book.Book_Author.Add(BA); } for (int i = 0; i < b.Category.Count; i++) { int ID = b.Category[i].ID; Category category = context.Categories.FirstOrDefault(c => c.ID == ID); Book_Category temp = new Book_Category(); temp.Category = category; temp.Book = book; book.Book_Category.Add(temp); } context.SaveChanges(); } return(true); } } catch (Exception ex) { LogService.log("Erro at Book Service", ex.StackTrace); return(false); } }
public static bool Add(Order o) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { context.Orders.Add(o); context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't add order to database. Detail: {0}", ex); } return(false); }
public static bool AddBook(BookData b) { Book book = new Book(); book.ISBN = b.ISBN; book.description = b.Description; book.name = b.Name; book.price = b.Price; book.quantity = b.Quantity; book.status = b.Status; book.year = b.Year; book.publisher_ID = b.Publisher_ID; try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { for (int i = 0; i < b.Author.Count; i++) { int ID = b.Author[i].ID; Author author = context.Authors.FirstOrDefault(a => a.ID == ID); Book_Author BA = new Book_Author(); BA.Author = author; BA.Book = book; book.Book_Author.Add(BA); } for (int i = 0; i < b.Category.Count; i++) { int ID = b.Category[i].ID; Category category = context.Categories.FirstOrDefault(c => c.ID == ID); Book_Category temp = new Book_Category(); temp.Category = category; temp.Book = book; book.Book_Category.Add(temp); } context.Books.Add(book); context.SaveChanges(); return(true); } } catch (Exception ex) { LogService.log("BOOK", ex.StackTrace); return(false); } }
public static List <AuthorData> GetAllBookAuthorData() { using (Book_Sale_ManagerEntities contex = new Book_Sale_ManagerEntities()) { List <Author> authors = contex.Authors.ToList(); List <AuthorData> result = new List <AuthorData>(); foreach (var item in authors) { AuthorData a = new AuthorData(); a.ID = item.ID; a.name = item.name; result.Add(a); } return(result); } }
public static bool Add(Account b) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { context.Accounts.Add(b); context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't add account to database. Detail: {0}", ex); return(false); } }
public static bool Update(Order o) { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { try { Order update = context.Orders.SingleOrDefault(x => x.ID == o.ID); if (update != null) { if (o.Account != null) { update.Account = o.Account; } if (o.account_ID != null) { update.account_ID = o.account_ID; } if (o.customer_name != null) { update.customer_name = o.customer_name; } if (o.date != null) { update.date = o.date; } if (o.Order_Detail != null) { update.Order_Detail = o.Order_Detail; } if (o.status != null) { update.status = o.status; } context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't update order. Detail: {0}", ex); } } return(false); }
public static bool Add(Author a) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { context.Authors.Add(a); context.SaveChanges(); Console.WriteLine("[AuthorService]: Add Author Successful!" + a.name); return(true); } } catch (Exception e) { LogService.log("Error", e.Message); return(false); } }
public static List <CategoryData> GetAllBookCategoryData() { using (Book_Sale_ManagerEntities contex = new Book_Sale_ManagerEntities()) { List <Category> categories = contex.Categories.ToList(); List <CategoryData> result = new List <CategoryData>(); foreach (var item in categories) { CategoryData i = new CategoryData(); i.ID = item.ID; i.name = item.name; i.status = item.status; result.Add(i); } return(result); } }
public static List <PublisherData> getAllPublisher() { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { List <Publisher> publishers = context.Publishers.ToList(); List <PublisherData> result = new List <PublisherData>(); foreach (var item in publishers) { PublisherData p = new PublisherData() { ID = item.ID, name = item.name }; result.Add(p); } return(result); } }
public static bool Remove(Account b) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { Account account = context.Accounts.FirstOrDefault(temp => temp.ID == b.ID); context.Accounts.Remove(account); context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't remove account from database. Detail: {0}", ex); return(false); } }
public static bool Add(Category c) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { context.Categories.Add(c); context.SaveChanges(); Console.WriteLine("[Category Add Successful!]" + c.name); context.Dispose(); return(true); } } catch (Exception e) { LogService.log("Error", e.Message); Console.WriteLine(e.StackTrace); return(false); } }
public static bool Remove(Category c) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { Category category = context.Categories.FirstOrDefault(t => t.ID == c.ID); context.Categories.Remove(category); context.SaveChanges(); Console.WriteLine("[Category Remove Successful!]" + c.name); context.Dispose(); return(true); } } catch (Exception e) { LogService.log("Error", e.Message); return(false); } }
public static bool Delete(Publisher p) { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { try { Publisher re = context.Publishers.SingleOrDefault(x => x.ID == p.ID); if (re != null) { context.Publishers.Remove(re); context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't delete order. Detail: {0}", ex); } } return(false); }
public static bool UpdateQuantity(int ID, int Quantity) { try { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { Book book = context.Books.FirstOrDefault(bo => bo.ID == ID); if (book != null) { book.quantity = Quantity; context.SaveChanges(); } return(true); } } catch (Exception ex) { LogService.log("Erro at Book Service", ex.StackTrace); return(false); } }
public static bool Update(Publisher p) { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { try { Publisher update = context.Publishers.SingleOrDefault(x => x.ID == p.ID); if (update != null) { if (p.name != null) { update.name = p.name; } context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't publisher order. Detail: {0}", ex); } } return(false); }
public static bool Update(Order_Detail o) { using (Book_Sale_ManagerEntities context = new Book_Sale_ManagerEntities()) { try { Order_Detail update = context.Order_Detail.SingleOrDefault(x => x.ID == o.ID); if (update != null) { if (o.Order != null) { update.Order = o.Order; } if (o.order_ID != null) { update.order_ID = o.order_ID; } if (o.quantity != null) { update.quantity = o.quantity; } if (o.book_ID != null) { update.book_ID = o.book_ID; } context.SaveChanges(); return(true); } } catch (Exception ex) { throw new Exception("Can't update order. Detail: {0}", ex); } } return(false); }