Example #1
0
        public ActionResult Create(BookViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                BookTable book = new BookTable();
                book.ISBN       = viewModel.ISBN1;
                book.BookStatus = false;

                BookDetailTable bookDetail = new BookDetailTable();
                bookDetail.ISBN    = viewModel.ISBN1;
                bookDetail.Title   = viewModel.Title1;
                bookDetail.Summary = viewModel.Summary1;
                if (viewModel.AuthorID1 == Convert.ToInt32(db.AuthorTables.Find(viewModel.AuthorID1).AuthorID))
                {
                    bookDetail.AuthorID = viewModel.AuthorID1;
                }

                if (viewModel.PublisherID1 == Convert.ToInt32(db.PublisherTables.Find(viewModel.PublisherID1).PublisherID))
                {
                    bookDetail.PublisherID = viewModel.PublisherID1;
                }

                db.BookTables.Add(book);
                db.BookDetailTables.Add(bookDetail);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("About", "Home"));
            }
        }
        public ActionResult Rent(int?id)
        {
            if (Session["UserID"] != null)
            {
                BookTable book = db.BookTables.Find(id);
                if (book.BookStatus == false)
                {
                    RentViewModel viewModel = new RentViewModel();
                    viewModel.UserID1 = Convert.ToInt32(Session["UserID"]);
                    BookDetailTable bookDetail = db.BookDetailTables.Find(id);
                    viewModel.BookDetailTable = bookDetail;
                    viewModel.BookTable       = book;
                    viewModel.RentDate1       = DateTime.Now;
                    viewModel.DueDate1        = DateTime.Now.AddDays(7);
                    viewModel.BookID1         = book.BookID;
                    viewModel.Deposit1        = 100000 + 3000 * 7;
                    viewModel.Cost1           = 3000;


                    return(View(viewModel));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #3
0
        public ActionResult Remove(int id)
        {
            BookTable       book       = db.BookTables.Find(id);
            BookDetailTable bookDetail = db.BookDetailTables.Find(id);

            db.BookTables.Remove(book);
            db.BookDetailTables.Remove(bookDetail);

            db.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
Example #4
0
        public ActionResult EditDetail(int id)
        {
            if (ModelState.IsValid)
            {
                BookDetailTable bookDetail = db.BookDetailTables.Find(id);

                if (TryUpdateModel(bookDetail, "", new string[] { "ISBN", "Title", "Summary", "AuthorID", "PublisherID" }))
                {
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Example #5
0
        public ActionResult Detail(int?id)
        {
            if (Session["UserID"] != null)
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                BookDetailTable bookDetail = db.BookDetailTables.Find(id);
                if (bookDetail == null)
                {
                    return(HttpNotFound());
                }
                return(View(bookDetail));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult EditRent(int?id)
        {
            if (Convert.ToBoolean(Session["IsAdmin"]) == true)
            {
                RentViewModel viewModel = new RentViewModel();
                viewModel.UserID1 = Convert.ToInt32(Session["UserID"]);
                BookDetailTable bookDetail = db.BookDetailTables.Find(id);
                BookTable       book       = db.BookTables.Find(id);
                RentDetailTable rentDetail = db.RentDetailTables.Find(id);
                RentTable       rent       = db.RentTables.Find(id);

                viewModel.RentTable       = rent;
                viewModel.RentDetailTable = rentDetail;
                viewModel.BookDetailTable = bookDetail;
                viewModel.BookTable       = book;
                return(View(viewModel));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Example #7
0
        public ActionResult EditDetail(int?id)
        {
            if (Convert.ToBoolean(Session["IsAdmin"]) == true)
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                BookDetailTable bookDetail = db.BookDetailTables.Find(id);

                if (bookDetail == null)
                {
                    return(HttpNotFound());
                }
                return(View(bookDetail));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public ActionResult Rent(int id, RentViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                BookDetailTable book       = db.BookDetailTables.Find(id);
                BookTable       book1      = db.BookTables.Find(id);
                RentDetailTable rentDetail = new RentDetailTable();
                rentDetail.BookID   = book1.BookID;
                rentDetail.UserID   = Convert.ToInt32(Session["UserID"]);
                rentDetail.ISBN     = book1.ISBN;
                rentDetail.RentDate = DateTime.Now;
                rentDetail.DueDate  = DateTime.Now.AddDays(7);
                rentDetail.Deposit  = 100000;
                rentDetail.Cost     = 3000;
                rentDetail.Paid     = 7 * rentDetail.Cost;
                rentDetail.Note     = viewModel.Note1;

                RentTable rent = new RentTable();
                rent.BookID   = rentDetail.BookID;
                rent.ISBN     = rentDetail.ISBN;
                rent.UserID   = Convert.ToInt32(Session["UserID"]);
                rent.RentDate = rentDetail.RentDate;
                rent.DueDate  = rentDetail.DueDate;

                book1.BookStatus = true;

                db.RentDetailTables.Add(rentDetail);
                db.RentTables.Add(rent);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("About", "Home"));
            }
        }