//mv 05-03-2019 public static bool returnBook(int idLender) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { LendsTable lend = db.LendsTable.Where(l => l.id == idLender).FirstOrDefault(); if (lend != null) { if (lend.statusCode == 2) { lend.BooksTable.isBorrowed = false; lend.statusCode = 4; lend.date = DateTime.Now; db.SaveChanges(); return(true); } } } } catch (Exception ex) { throw ex; } return(false); }
public static bool rejectBorrow(int idBorrow) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { LendsTable lend = db.LendsTable.Where(l => l.id == idBorrow).FirstOrDefault(); if (lend != null) { if (lend.statusCode == 1) { lend.statusCode = 3; BooksTable bt = db.BooksTable.Where(b => b.id == lend.bookId).FirstOrDefault(); if (bt != null) { bt.isBorrowed = false; } db.SaveChanges(); return(true); } } } } catch (Exception ex) { throw ex; } return(false); }
public static void deleteBook(int idB) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { BooksTable b = db.BooksTable.Where(book => book.id == idB).First(); b.isDeleted = true; db.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public static bool RateBook(RatingTable rating) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { db.RatingTable.Add(rating); db.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static string deleteUser(int uId) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { db.UsersTable.Remove(db.UsersTable.Find(uId)); db.SaveChanges(); } return("ok"); } catch (Exception ex) { throw ex; } }
public static UsersTable InsertUser(UsersTable newUser) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { db.UsersTable.Add(newUser); db.SaveChanges(); return(newUser); } } catch (Exception ex) { throw ex; } }
public static void addBookToMybasket(MyBasketOfBooks bas) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { db.MyBasketOfBooks.Add(bas); //???????????????????????????????????????????????????? db.SaveChanges(); } return; } catch (Exception ex) { throw ex; } }
//????????????????????????? public static string updateUser(UsersTable u) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { UsersTable u1 = db.UsersTable.Where(i => i.id == u.id).First(); u1.birthDate = u.birthDate; db.SaveChanges(); } return("ok"); } catch (Exception ex) { throw ex; } }
public static void PromoteNumberOfViewers(int idBook) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { BooksTable bt = db.BooksTable.Where(b => b.id == idBook).FirstOrDefault(); if (bt != null) { bt.numberOfViewers++; db.SaveChanges(); } } } catch (Exception) { } }
public static bool borrowBook(LendsTable lend) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { db.LendsTable.Add(lend); BooksTable b = db.BooksTable.Where(x => x.id == lend.bookId).FirstOrDefault(); b.isBorrowed = true; db.SaveChanges(); } return(true); } catch (Exception ex) { throw ex; } return(false); }
public static void saveImageName(int idBook, string bookName) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { BooksTable book = db.BooksTable.Where(b => b.id == idBook).FirstOrDefault(); if (book != null) { book.picNAme = bookName; db.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public static int rateBook(RatingTable b) { int idB; try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { db.RatingTable.Add(b); //???????????????????????????????????????????????????? db.SaveChanges(); idB = b.id; } return(idB); } catch (Exception ex) { throw ex; } }
public static bool updateWhenBookIsAvailable(waitingForAbookTable userWait) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { if (db.waitingForAbookTable.Any(w => w.bookCode == userWait.bookCode && w.userCode == userWait.userCode) == false) { db.waitingForAbookTable.Add(userWait); db.SaveChanges(); } } return(true); } catch (Exception ex) { throw ex; } return(false); }
public static string EditUser(UsersTable newUser) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { UsersTable u = db.UsersTable.Where(x => x.id == newUser.id).FirstOrDefault(); if (u != null) { u.firstName = newUser.firstName; u.lastName = newUser.lastName; u.email = newUser.email; u.phone = newUser.phone; u.neighborhood = newUser.neighborhood; u.address = newUser.address; u.houseNumber = newUser.houseNumber; if (newUser.cityCode != 0) { u.cityCode = newUser.cityCode; } else { u.CityTable = new CityTable() { name = newUser.CityTable.name }; } u.birthDate = newUser.birthDate; u.password = newUser.password; u.genderId = newUser.genderId; } db.SaveChanges(); } return("ok"); } catch (Exception ex) { throw ex; } }
public static void deleteBookFromMyBuskate(int idB, int idU) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { List <MyBasketOfBooks> busketList = db.MyBasketOfBooks.Where(x => x.idUser == idU).ToList(); if (busketList.Count > 0) { MyBasketOfBooks busketBookToRemove = busketList.Where(x => x.idBook == idB).FirstOrDefault(); if (busketBookToRemove != null) { db.MyBasketOfBooks.Remove(busketBookToRemove); db.SaveChanges(); } } } } catch (Exception ex) { throw ex; } }
public static void editBook(BooksTable book) { try { using (BooksLibraryProjectEntities db = new BooksLibraryProjectEntities()) { BooksTable booktable = db.BooksTable.Where(x => x.id == book.id).FirstOrDefault(); if (booktable != null) { if (book.autherId != 0) { booktable.autherId = book.autherId; } else { // db.PublishingTable. booktable.AutherTable = new AutherTable() { name = book.AutherTable.name }; } if (book.nameId != 0) { booktable.nameId = book.nameId; } else { // db.PublishingTable. booktable.BooksNameTable = new BooksNameTable() { name = book.BooksNameTable.name }; } booktable.categoryId = book.categoryId; booktable.description = book.description; booktable.numOfPages = book.numOfPages; if (book.publishingId != 0) { booktable.publishingId = book.publishingId; } else { booktable.PublishingTable = new PublishingTable() { name = book.PublishingTable.name }; } } //???????????????????????????????????????????????????? db.SaveChanges(); } return; } catch (Exception ex) { throw ex; } }