Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostBorrow(int id)
        {
            var book = await _db.Book.FindAsync(id);

            var borrowed = new BorrowedList();

            byte[] userId;
            HttpContext.Session.TryGetValue("UserId", out userId);
            borrowed.UserId = Int32.Parse(System.Text.Encoding.UTF8.GetString(userId));
            borrowed.BookId = id;
            if (book == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                var BookFromDb = await _db.Book.FindAsync(id);

                BookFromDb.IsBorrowed = "Yes";
                await _db.BorrowedLists.AddAsync(borrowed);

                await _db.SaveChangesAsync();

                return(RedirectToPage("Index"));
            }

            return(RedirectToPage("Index"));
        }
Ejemplo n.º 2
0
        public IActionResult OnPost(string profile, string returnBookId)
        {
            if (profile == "Logout")
            {
                HttpContext.Session.Remove("UserId");
                HttpContext.Session.Remove("UserLogin");
                HttpContext.Session.Remove("UserEmail");

                return(new RedirectToPageResult("../Login"));
            }
            else if (profile == "Edit")
            {
                return(new RedirectToPageResult("./Edit"));
            }


            if (returnBookId.Length > 0)
            {
                Book BookFromDb = _db.Book.Find(Int32.Parse(returnBookId));
                BookFromDb.IsBorrowed = "No";

                BorrowedList[] borrowedArray = _db.BorrowedLists.ToArray();
                BorrowedList   borrowed      = null;
                foreach (BorrowedList b in borrowedArray)
                {
                    if (b.BookId == Int32.Parse(returnBookId))
                    {
                        borrowed = b;
                        break;
                    }
                }

                _db.BorrowedLists.Remove(borrowed);
                _db.SaveChanges();

                var    userId = "";
                byte[] valueID;

                HttpContext.Session.TryGetValue("UserId", out valueID);
                try
                {
                    userId = System.Text.Encoding.UTF8.GetString(valueID);
                }
                catch (Exception e) { }

                borriwedBooks = getUserBorrowedBooks(Int32.Parse(userId));
            }

            return(Page());
        }
Ejemplo n.º 3
0
        public List <BorrowedList> readBorrowedBooks(int ID)
        {
            cmd.Connection = cn;
            List <BorrowedList> bbl = new List <BorrowedList>();
            BorrowedList        d;

            try
            {
                cn.Open();
                cmd.CommandText = "select books.book_ID,title,author,date_taken,last_return_date from books, takes where takes.stu_ID='" + ID + "' and takes.book_ID=books.book_ID";
                dr = cmd.ExecuteReader();
                int k = 0;
                while (dr.Read())
                {
                    d            = new BorrowedList();
                    d.book_ID    = dr[0].ToString();
                    d.title      = dr[1].ToString();
                    d.author     = dr[2].ToString();
                    d.takenDate  = dr[3].ToString();
                    d.returnDate = dr[4].ToString();
                    bbl.Add(d);
                }
                cn.Close();
                //Book.k = k;
                return(bbl);
            }
            catch (Exception el)
            {
                MessageBox.Show(el.Message);
                return(null);
            }

            /*cmd.Connection = cn;
             * Book[] d = new Book[30];
             * for (int i = 0; i < 30; i++)
             * {
             *  d[i] = new Book();
             * }
             * try
             * {
             *  cn.Open();
             *  cmd.CommandText = "select * from books where book_ID in (select book_ID from takes where stu_ID = '"+ID+"')";
             *  dr = cmd.ExecuteReader();
             *  int k = 0;
             *  while (dr.Read())
             *  {
             *      d[k].ID = dr[0].ToString();
             *      d[k].title = dr[1].ToString();
             *      d[k].author = dr[2].ToString();
             *      d[k].popularity = Convert.ToInt32(dr[3].ToString());
             *      d[k].quantity = Convert.ToInt32(dr[4].ToString());
             *      d[k].condition = dr[5].ToString();
             *      d[k].deadline = Convert.ToInt32(dr[6].ToString());
             *      k++;
             *  }
             *  cn.Close();
             *  Book.k = k;
             *  return d;
             * }
             * catch (Exception el)
             * {
             *  MessageBox.Show(el.Message);
             *  return null;
             * }*/
        }