// GET: EditBook
        public ActionResult Index()
        {
            account a = (account)Session["user"];

            if (a != null)
            {
                if (a.Role)
                {
                    int                    bid        = Int32.Parse(Request["bid"]);
                    AuthorDAO              authorDAO  = new AuthorDAO();
                    categoryDAO            cdb        = new categoryDAO();
                    book                   b          = new BookDAO().getOne(bid);
                    List <author>          authors    = authorDAO.getAll();
                    List <category>        categories = cdb.getAll();
                    List <book_categories> bcats      = cdb.getAllss();
                    dynamic                dy         = new ExpandoObject(); // dynamic - multiple model
                    dy.book    = b;
                    dy.cates   = categories;
                    dy.bcats   = bcats;
                    dy.authors = authors;
                    dy.author  = authorDAO.getAuthorByBookID(bid);
                    return(View(dy));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }
예제 #2
0
        // GET: Search
        public ActionResult Index()
        {
            BookDAO     bd        = new BookDAO();
            categoryDAO cd        = new categoryDAO();
            string      txt       = Request["text"];
            int         pageIndex = 1;

            if (Request.QueryString["pageIndex"] != null)
            {
                pageIndex = Int32.Parse(Request.QueryString["pageIndex"]);
            }
            int pageSize = 2;
            // Count all homes in database (Table Home)
            int total = bd.getbyname(txt, 1, 1000).Count;
            // IF count % pageSize == 0 => totalPage = count / pageSize
            int totalPage = total / pageSize;

            if (total % pageSize != 0)
            {
                totalPage += 1;
            }

            // Display total of page to Home page for pagging
            ViewData["totalPage"] = totalPage;
            // Display pageIndex to active page current
            ViewData["pageIndex"] = pageIndex;
            ViewData["text"]      = txt;
            dynamic dy = new ExpandoObject(); // dynamic - multiple model

            dy.cates = cd.getAll();
            dy.books = bd.getbyname(txt, pageIndex, pageSize);

            return(View(dy));
        }
        // GET: Detail
        public ActionResult Index()
        {
            string id_raw = Request.QueryString["bookid"];

            if (id_raw == null)
            {
                id_raw = Session["id"].ToString();
            }
            int id = Int32.Parse(id_raw);

            Session.Remove("id");


            commentDAO     cbd      = new commentDAO();
            List <comment> comments = cbd.getbyBook(id);
            List <author>  authors  = new AuthorDAO().getAuthorByBookID(id);
            categoryDAO    cd       = new categoryDAO();
            BookDAO        db       = new BookDAO();
            int            count    = comments.Count;
            dynamic        dy       = new ExpandoObject();

            dy.book           = db.getOne(id);
            ViewData["count"] = count;
            dy.cates          = cd.getAll();
            dy.comments       = comments;
            dy.authors        = authors;
            if (Session["user"] != null)
            {
                account a = (account)Session["user"];
                new historyDAO().addHistory(a.username, id);
            }
            return(View(dy));
        }
        public ActionResult IndexPost(HttpPostedFileBase img)
        {
            //get id of current book
            int bid = Int32.Parse(Request["bid"]);

            string[] category_ids = Request["category"].Split(',');
            string   title        = Request["title"];
            //string img = Request["img"];
            string  languge = Request["language"];
            string  des     = Request["description"];
            account a       = (account)Session["user"];
            BookDAO bd      = new BookDAO();;
            book    b       = bd.getOne(bid);

            b.name     = title;
            b.img      = "img";
            b.language = languge;
            b.des      = des;
            bd.updateBook(b);
            //remove all old categories
            categoryDAO cd = new categoryDAO();

            cd.removeCateOfBook(bid);
            //add categories
            for (int i = 0; i < category_ids.Length - 1; i++)
            {
                int cid = Int32.Parse(category_ids[i]);
                bd.addCforlast(cid, bid);
            }
            AuthorDAO authorDAO = new AuthorDAO();

            //check if book's author is already existed
            if (Request["isNewAuthor"] == null)
            {
                //add a connection between book and author
                int aid = Int32.Parse(Request["authorid"]);
                authorDAO.AddAuthorForBook(aid, bid);
            }
            else
            {
                //create new author
                string author_name = Request["author_name"];
                string lifestory   = Request["lifestory"];
                string nation      = Request["nation"];
                string dob         = DateTime.Parse(Request["dob"]).ToString("yyyy-MM-dd");
                authorDAO.AddAuthor(author_name, lifestory, nation, dob);
                //add a connection between book and new author
                authorDAO.AddAuthorForBook(authorDAO.getLastId(), bid);
            }
            if (img.ContentLength > 0)
            {
                var    extenstion    = Path.GetExtension(img.FileName);
                string fileName      = "i" + bid + extenstion;
                string savedFileName = Server.MapPath("~/assets/img/book/" + fileName);
                img.SaveAs(savedFileName);
                bd.updateBook(new book(bid, des, title, des, a, languge, fileName, DateTime.Now, 0, 0));
            }
            return(RedirectToAction("Index", "Manage"));
        }
        public ActionResult IndexPost()
        {
            //get id of current book
            int bid = Int32.Parse(Request["bid"]);

            string[] category_ids = Request["category"].Split(',');
            string   title        = Request["title"];
            string   img          = Request["img"];
            string   languge      = Request["language"];
            string   des          = Request["description"];
            account  a            = (account)Session["user"];
            BookDAO  bd           = new BookDAO();;
            book     b            = bd.getOne(bid);

            b.name     = title;
            b.img      = img;
            b.language = languge;
            b.des      = des;
            bd.updateBook(b);
            //remove all old categories
            categoryDAO cd = new categoryDAO();

            cd.removeCateOfBook(bid);
            //add categories
            for (int i = 0; i < category_ids.Length - 1; i++)
            {
                int cid = Int32.Parse(category_ids[i]);
                bd.addCforlast(cid, bid);
            }
            AuthorDAO authorDAO = new AuthorDAO();

            //check if book's author is already existed
            if (Request["isNewAuthor"] == null)
            {
                //add a connection between book and author
                int aid = Int32.Parse(Request["authorid"]);
                authorDAO.AddAuthorForBook(aid, bid);
            }
            else
            {
                //create new author
                string author_name = Request["author_name"];
                string lifestory   = Request["lifestory"];
                string nation      = Request["nation"];
                string dob         = DateTime.Parse(Request["dob"]).ToString("yyyy-MM-dd");
                authorDAO.AddAuthor(author_name, lifestory, nation, dob);
                //add a connection between book and new author
                authorDAO.AddAuthorForBook(authorDAO.getLastId(), bid);
            }
            return(RedirectToAction("Index", "Manage"));
        }
        // GET: ProfileView
        public ActionResult Index()
        {
            account a  = (account)Session["user"];
            dynamic dy = new ExpandoObject();

            dy.acc = a;
            categoryDAO cd = new categoryDAO();

            dy.cates = cd.getAll();
            commentDAO     cbd      = new commentDAO();
            List <comment> co       = cbd.getbyUser(a.username);
            int            countcmt = co.Count;

            ViewData["countcmt"] = countcmt;
            ViewBag.notifi       = Session["noti"];
            Session.Remove("noti");
            return(View(dy));
        }
예제 #7
0
        // GET: Manage
        public ActionResult Index()
        {
            account a = (account)Session["user"];

            if (a != null)
            {
                if (a.Role)
                {
                    BookDAO                db         = new BookDAO();
                    accountDAO             adb        = new accountDAO();
                    categoryDAO            cdb        = new categoryDAO();
                    commentDAO             cd         = new commentDAO();
                    AuthorDAO              authorDAO  = new AuthorDAO();
                    List <author>          authors    = authorDAO.getAll();
                    List <book>            books      = db.getAll(1000, 1);
                    List <comment>         comments   = cd.getAll();
                    List <account>         accounts   = adb.getAll();
                    List <category>        categories = cdb.getAll();
                    List <book_categories> bcats      = cdb.getAllss();
                    dynamic                dy         = new ExpandoObject(); // dynamic - multiple model
                    dy.books           = books;
                    dy.cates           = categories;
                    dy.bcats           = bcats;
                    dy.comments        = comments;
                    dy.accounts        = accounts;
                    dy.authors         = authors;
                    ViewData["countb"] = db.getAll(1000, 1).Count;
                    ViewData["counta"] = accounts.Count;
                    ViewData["countc"] = comments.Count;
                    return(View(dy));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Login"));
            }
        }