Beispiel #1
0
 public Book Get_Book_By_Id(int id)
 {
     using (var bookDbContext = new LibraryDBContext())
     {
         return(bookDbContext.Books.Find(id));
     }
 }
Beispiel #2
0
        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);
 }
Beispiel #4
0
        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"));
                }
            }
        }
Beispiel #5
0
        // 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;
 }
Beispiel #7
0
        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"));
            }
        }
Beispiel #8
0
 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();
     }
 }
Beispiel #10
0
 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();
     }
 }
Beispiel #11
0
 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();
     }
 }
Beispiel #12
0
 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();
     }
 }
Beispiel #14
0
 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();
     }
 }
Beispiel #16
0
        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();
     }
 }
Beispiel #18
0
 public Book Update_Book(Book book)
 {
     using (var bookDbContext = new LibraryDBContext())
     {
         bookDbContext.Books.Update(book);
         bookDbContext.SaveChanges();
         return(book);
     }
 }
Beispiel #19
0
        public IActionResult deleteUser(string currentUser)
        {
            LibraryDBContext db = new LibraryDBContext();

            db.AspNetUsers.Remove(FindUser(currentUser));
            db.SaveChanges();

            return(View("Admin"));
        }
Beispiel #20
0
 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);
     }
 }
Beispiel #21
0
 public void Delete_Book(int id)
 {
     using (var bookDbContext = new LibraryDBContext())
     {
         var getBookById = Get_Book_By_Id(id);
         bookDbContext.Books.Remove(getBookById);
         bookDbContext.SaveChanges();
     }
 }
Beispiel #22
0
 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();
     }
 }
Beispiel #23
0
        public List <Employee> GetAll()
        {
            List <Employee> employees;

            using (context = new LibraryDBContext())
            {
                employees = new List <Employee>(context.Employees.Include("Branch"));
            }
            return(employees);
        }
Beispiel #24
0
        public Employee GetById(int id)
        {
            Employee worker;

            using (context = new LibraryDBContext())
            {
                worker = context.Employees.AsQueryable().FirstOrDefault(x => x.Id == id).Clone();
            }
            return(worker);
        }
Beispiel #25
0
        public List <User> GetAll()
        {
            List <User> users;

            using (context = new LibraryDBContext())
            {
                users = new List <User>(context.Users);
            }
            return(users);
        }
Beispiel #26
0
        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);
        }
Beispiel #29
0
        public RentedBook GetById(int id)
        {
            RentedBook book;

            using (context = new LibraryDBContext())
            {
                book = context.RentedBooks.AsQueryable().FirstOrDefault(x => x.Id == id);
            }
            return(book);
        }
Beispiel #30
0
        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);
        }