public Book Get_Book_By_Id(int id) { using (var bookDbContext = new LibraryDBContext()) { return(bookDbContext.Books.Find(id)); } }
public List <Book> UpdateLibrary(List <Book> library) { LibraryDBContext db = new LibraryDBContext(); library = db.Book.ToList <Book>(); return(library); }
public CtphieuNhapController(LibraryDBContext context, IConfiguration configuration) { _context = context; _configuration = configuration; apiAddress = _configuration.GetSection("ApiAddress").GetSection("Url").Value; _apiService = ApiService.GetAPI(apiAddress); }
public IActionResult Menu(string menu) { switch (menu) { case null: return(View()); case "manage": return(View("Admin")); case "search": return(View("Search")); case "library": return(View("Browse")); default: List <Transaction> checkedOut = UserBook(); List <Book> userOut = new List <Book>(); LibraryDBContext db = new LibraryDBContext(); if (checkedOut.Count > 0) { return(View("Return", checkedOut)); } else { return(View("Return")); } } }
// User Functions public IActionResult CheckOut(string book) { LibraryDBContext db = new LibraryDBContext(); Book tempBook = new Book(); foreach (Book entry in db.Book) { if (entry.Title == book) { tempBook = entry; tempBook.Checkedout += 1; tempBook.Available -= 1; db.Book.Update(tempBook); } } AspNetUsers currentUser = FindCurrentUser(); DateTime DueDate = DateTime.Now; DueDate = DueDate.AddDays(14); db.Transaction.Update(new Transaction() { Userid = User.Identity.Name, Booktitle = JsonSerializer.Serialize <Book>(tempBook), Duedate = DueDate, Renew = "false" }); TempData["Check"] = tempBook.Title; db.SaveChanges(); return(RedirectToAction("Search")); }
public AuthenticateController(UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, IConfiguration configuration, LibraryDBContext libraryDBContext) { _userManager = userManager; _roleManager = roleManager; _configuration = configuration; _libraryDbContext = libraryDBContext; }
public IActionResult ReturnBook(string book) { LibraryDBContext db = new LibraryDBContext(); Book tempBook = new Book(); foreach (Book entry in db.Book) { if (entry.Title == book) { tempBook = entry; tempBook.Checkedout -= 1; tempBook.Available += 1; db.Book.Update(tempBook); } } AspNetUsers currentUser = FindCurrentUser(); foreach (Transaction check in db.Transaction) { if ((JsonSerializer.Deserialize <Book>(check.Booktitle)).Id == tempBook.Id && check.Userid == currentUser.Id) { db.Remove(check); } } db.SaveChanges(); List <Transaction> checkedOut = UserBook(); List <Book> userOut = new List <Book>(); if (checkedOut.Count > 0) { foreach (Transaction check in checkedOut) { foreach (Book books in db.Book) { if ((JsonSerializer.Deserialize <Book>(check.Booktitle)).Id == books.Id) { if (check.Duedate > DateTime.Now) { TempData["Date"] = check.Duedate.ToShortDateString(); userOut.Add(books); } else { TempData["Message"] = "Book Overdue!"; userOut.Add(books); } } } } return(View("Return", userOut)); } else { return(RedirectToAction("Return")); } }
public void Add(RentedBook rentedBook) { using (context = new LibraryDBContext()) { context.RentedBooks.Add(rentedBook); context.SaveChanges(); } }
public void Add(SoldBook soldBook) { using (context = new LibraryDBContext()) { context.SoldBooks.Add(soldBook); context.SaveChanges(); } }
public void Remove(User user) { using (context = new LibraryDBContext()) { User newUser = context.Users.FirstOrDefault(x => x.Id == user.Id); context.Users.Remove(newUser); context.SaveChanges(); } }
public void Remove(Employee employee) { using (context = new LibraryDBContext()) { Employee newEmployee = context.Employees.FirstOrDefault(x => x.Id == employee.Id); context.Employees.Remove(newEmployee); context.SaveChanges(); } }
private void LoadCategories() { using (LibraryDBContext libraryDbContext = new LibraryDBContext()) { cbxAddKitapCategory.DataSource = libraryDbContext.Kategoris.ToList(); cbxAddKitapCategory.DisplayMember = "KategoriAdi"; cbxAddKitapCategory.ValueMember = "Id"; } }
public void Remove(SoldBook soldBook) { using (context = new LibraryDBContext()) { SoldBook newSoldBook = context.SoldBooks.FirstOrDefault(x => x.Id == soldBook.Id); context.SoldBooks.Remove(newSoldBook); context.SaveChanges(); } }
public void Remove(Book entity) { using (context = new LibraryDBContext()) { Book book = context.Books.FirstOrDefault(x => x.Id == entity.Id); context.Books.Remove(book); context.SaveChanges(); } }
public void Remove(Customer customer) { using (context = new LibraryDBContext()) { Customer newCustomer = context.Customers.FirstOrDefault(x => x.Id == customer.Id); context.Customers.Remove(newCustomer); context.SaveChanges(); } }
public PhieuMuonController(LibraryDBContext context, IConfiguration configuration, IHostingEnvironment appEnvironment) { _context = context; _configuration = configuration; _appEnvironment = appEnvironment; apiAddress = _configuration.GetSection("ApiAddress").GetSection("Url").Value; _apiService = ApiService.GetAPI(apiAddress); }
public void Remove(Branch branch) { using (context = new LibraryDBContext()) { Branch newBranch = context.Branches.FirstOrDefault(x => x.Id == branch.Id); context.Branches.Remove(newBranch); context.SaveChanges(); } }
public Book Update_Book(Book book) { using (var bookDbContext = new LibraryDBContext()) { bookDbContext.Books.Update(book); bookDbContext.SaveChanges(); return(book); } }
public IActionResult deleteUser(string currentUser) { LibraryDBContext db = new LibraryDBContext(); db.AspNetUsers.Remove(FindUser(currentUser)); db.SaveChanges(); return(View("Admin")); }
public List <Book> Get_All_Books() { using (var bookDbContext = new LibraryDBContext()) { var getBooks = bookDbContext.Books.FromSqlRaw(@"Select Books.*, Categories.CategoryName from Books Inner Join Categories on Books.CategoryId = Categories.Id; ").ToList(); return(getBooks); } }
public void Delete_Book(int id) { using (var bookDbContext = new LibraryDBContext()) { var getBookById = Get_Book_By_Id(id); bookDbContext.Books.Remove(getBookById); bookDbContext.SaveChanges(); } }
public void Remove(RentedBook rentedBook) { using (context = new LibraryDBContext()) { RentedBook newRentedBook = context.RentedBooks.FirstOrDefault(x => x.Id == rentedBook.Id); context.RentedBooks.Remove(newRentedBook); context.SaveChanges(); } }
public List <Employee> GetAll() { List <Employee> employees; using (context = new LibraryDBContext()) { employees = new List <Employee>(context.Employees.Include("Branch")); } return(employees); }
public Employee GetById(int id) { Employee worker; using (context = new LibraryDBContext()) { worker = context.Employees.AsQueryable().FirstOrDefault(x => x.Id == id).Clone(); } return(worker); }
public List <User> GetAll() { List <User> users; using (context = new LibraryDBContext()) { users = new List <User>(context.Users); } return(users); }
public User GetById(int id) { User user; using (context = new LibraryDBContext()) { user = context.Users.AsQueryable().FirstOrDefault(x => x.Id == id); } return(user); }
public List <Customer> GetAll() { List <Customer> customers; using (context = new LibraryDBContext()) { customers = new List <Customer>(context.Customers); } return(customers); }
public Customer GetById(int id) { Customer customer; using (context = new LibraryDBContext()) { customer = context.Customers.AsQueryable().FirstOrDefault(x => x.Id == id).Clone(); } return(customer); }
public RentedBook GetById(int id) { RentedBook book; using (context = new LibraryDBContext()) { book = context.RentedBooks.AsQueryable().FirstOrDefault(x => x.Id == id); } return(book); }
public List <RentedBook> GetAll() { List <RentedBook> soldBooks; using (context = new LibraryDBContext()) { soldBooks = new List <RentedBook>(context.RentedBooks.Include("Book").Include("User").Include("Client")); } return(soldBooks); }