Beispiel #1
0
        //
        // GET: /Books/Edit/5
        public ActionResult Edit(string id)
        {
            //DangVH. Create. Start (02/11/2016)
            ViewBag.cloudinary = cloudinary;
            //DangVH. Create. End (02/11/2016)
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            var book                    = Context.Books.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
            var allCategory             = Context.Categories.Find(_ => true).ToEnumerable();
            var bookCategoriesViewModel = new List <BookCategoriesViewModel>();
            var selectedPublisherValue  = book.Publishers.ToString();
            var selectedCategoryValue   = book.Categories.ToString();

            ViewBag.publisherId = GetPubsCats(selectedPublisherValue.Split(','), 1);
            ViewBag.categoryId  = GetPubsCats(selectedCategoryValue.Split(','), 2);
            //foreach (var category in allCategory)
            //{
            //    bookCategoriesViewModel.Add(new BookCategoriesViewModel()
            //    {
            //        CategoryId = category.Id,
            //        CategoryName = category.CategoryName,
            //        IsSelected = book.Categories.Where(x => x.CategoryId == category.Id).Any()
            //    });
            //}
            //book.Categories = bookCategoriesViewModel;
            return(View(book));
        }
Beispiel #2
0
 //
 // GET: /Books/Create
 public ActionResult Create()
 {
     ViewBag.bookNumber  = BooksControllerHelper.GetBookNumber();
     ViewBag.CategoryId  = GetPubsCats(null, 2);
     ViewBag.PublisherId = GetPubsCats(null, 1);
     return(View());
 }
Beispiel #3
0
 //
 // GET: /Books/Edit/5
 public ActionResult Edit(string id)
 {
     if (Context.Users.Find(x => x.Id.Equals(User.Identity.GetUserId())).FirstOrDefault().Roles.Contains("admin"))
     {
         //DangVH. Create. Start (02/11/2016)
         ViewBag.cloudinary = cloudinary;
         //DangVH. Create. End (02/11/2016)
         var allBook = Context.Books.Find(_ => true).ToList();
         if (allBook.Where(x => x.Id.Equals(id)).Any() == false)
         {
             ViewBag.errorMessage = "Không có kết quả!";
             return(View("NotFoundError"));
         }
         else
         {
             var book = Context.Books.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
             var selectedPublisherValue = book.Publishers.ToString();
             var selectedCategoryValue  = book.Categories.ToString();
             var selectedAuthorValue    = book.Authors.ToString();
             ViewBag.publisherId = GetPubsCatsAus(selectedPublisherValue.Split(','), 1);
             ViewBag.categoryId  = GetPubsCatsAus(selectedCategoryValue.Split(','), 2);
             ViewBag.authorId    = GetPubsCatsAus(selectedAuthorValue.Split(','), 3);
             ViewBag.bookNumber  = BooksControllerHelper.GetBookNumber();
             //DangVH. Create. End (14/11/2016)
             return(View(book));
         }
     }
     else
     {
         ViewBag.errorMessage = "Bạn không có quyền truy cập vào chức năng này";
         return(View("NotFoundError"));
     }
 }
Beispiel #4
0
        public ActionResult Edit(Book book)
        {
            var listBook = Context.Books.Find(_ => true).ToList();

            foreach (var eachBook in listBook)
            {
                if (eachBook.BookName.ToLower().Equals(book.BookName.ToLower()) &&
                    listBook.Find(x => x.BookName.ToLower().Equals(book.BookName.ToLower())).Id != book.Id)
                {
                    ModelState.AddModelError("BookName", "Tên sách đã tồn tại");
                }
            }
            if (ModelState.IsValid)
            {
                // TODO: Add update logic here
                //DangVH. Create. Start (02/11/2016)
                {
                    var file         = Request.Files[0];
                    var uploadResult = ImageUploadHelper.GetUploadResult(file);
                    //DangVH. Create. End (02/11/2016)
                    var editBook = Context.Books.Find(x => x.Id.Equals(new ObjectId(book.Id))).FirstOrDefault();
                    editBook.BookName    = book.BookName;
                    editBook.Authors     = book.Authors;
                    editBook.ReleaseDay  = book.ReleaseDay.ToLocalTime();
                    editBook.Description = book.Description;
                    if (file.ContentLength == 0)
                    {
                        editBook.ImgPublicId = book.ImgPublicId;
                    }
                    else
                    {
                        editBook.ImgPublicId = uploadResult.PublicId;
                    }
                    editBook.Categories.Clear();
                    //DangVH. Create. Start (14/11/2016)
                    editBook.Publishers.Clear();
                    foreach (var publisherId in book.Publishers)
                    {
                        editBook.Publishers.Add(publisherId);
                    }

                    foreach (var categoryId in book.Categories)
                    {
                        editBook.Categories.Add(categoryId);
                    }
                    //DangVH. Create. End (14/11/2016)
                    Context.Books.ReplaceOneAsync(x => x.Id.Equals(new ObjectId(book.Id)), editBook);
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            var selectedPublisherValue = book.Publishers.ToString();
            var selectedCategoryValue  = book.Categories.ToString();

            ViewBag.publisherId = GetPubsCats(selectedPublisherValue.Split(','), 1);
            ViewBag.categoryId  = GetPubsCats(selectedCategoryValue.Split(','), 2);
            ViewBag.cloudinary  = cloudinary;
            return(View(book));
        }
Beispiel #5
0
        public ActionResult Create(Book book)
        {
            var listBook = Context.Books.Find(_ => true).ToList();
            var file     = Request.Files[0];

            if (file.ContentLength == 0)
            {
                ModelState.AddModelError("ImgPublicId", "Ảnh sách bắt buộc");
            }
            foreach (var eachBook in listBook)
            {
                if (book.BookName != null && eachBook.BookName.ToLower().Equals(book.BookName.ToLower()))
                {
                    ModelState.AddModelError("BookName", "Tên sách đã tồn tại");
                }
            }
            if (ModelState.IsValid)
            {
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                var addBook      = new Book()
                {
                    BookName = book.BookName,
                    Authors  = book.Authors,
                    //DangVH. Delete. Start (14/11/2016)
                    //Publishers = book.Publishers,
                    //DangVH. Delete. End (14/11/2016)
                    ReleaseDay  = book.ReleaseDay.ToLocalTime(),
                    Description = book.Description,
                    ImgPublicId = uploadResult.PublicId
                };
                foreach (var publisherId in book.Publishers)
                {
                    addBook.Publishers.Add(publisherId);
                }

                foreach (var categoryId in book.Categories)
                {
                    addBook.Categories.Add(categoryId);
                }
                //DangVH. Create. End (14/11/2016)
                Context.Books.InsertOneAsync(addBook);
                return(RedirectToAction("Index"));
            }
            //DangVH. Update. Start (14/11/2016)
            //Book newbook = BooksControllerHelper.GetCheckBoxValues();
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            var selectedPublisherValue = book.Publishers.ToString();
            var selectedCategoryValue  = book.Categories.ToString();

            ViewBag.publisherId = GetPubsCats(selectedPublisherValue.Split(','), 1);
            ViewBag.categoryId  = GetPubsCats(selectedCategoryValue.Split(','), 2);
            //DangVH. Update. End (14/11/2016)
            return(View(book));
        }
Beispiel #6
0
 //
 // GET: /Books/Create
 public ActionResult Create()
 {
     //Book book = BooksControllerHelper.GetCheckBoxValues();
     ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
     //DangVH. Create. Start (10/11/2016)
     //var publishers = Context.Publishers.Find(_ => true).ToEnumerable();
     ViewBag.CategoryId  = GetPubsCats(null, 2);
     ViewBag.PublisherId = GetPubsCats(null, 1);
     //DangVH. Create. End (10/11/2016)
     //return PartialView("_Create", book);
     return(View());
 }
Beispiel #7
0
        //
        // GET: /Books/Edit/5
        public ActionResult Edit(string id)
        {
            //DangVH. Create. Start (02/11/2016)
            ViewBag.cloudinary = cloudinary;
            //DangVH. Create. End (02/11/2016)
            var book = Context.Books.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
            var selectedPublisherValue = book.Publishers.ToString();
            var selectedCategoryValue  = book.Categories.ToString();

            ViewBag.publisherId = GetPubsCats(selectedPublisherValue.Split(','), 1);
            ViewBag.categoryId  = GetPubsCats(selectedCategoryValue.Split(','), 2);
            ViewBag.bookNumber  = BooksControllerHelper.GetBookNumber();
            //DangVH. Create. End (14/11/2016)
            return(View(book));
        }
Beispiel #8
0
        //DangVH. Create. End (14/11/2016)


        //
        // GET: /Books/
        public ActionResult Index(string searchString)
        {
            //DangVH. Create. Start (02/11/2016)
            ViewBag.currentUser = User.Identity.GetUserName();
            ViewBag.bookNumber  = BooksControllerHelper.GetBookNumber();
            //DangVH. Create. End (02/11/2016)
            ViewBag.allCategories = BooksControllerHelper.ListAllCategory();
            ViewBag.allPublishers = Context.Publishers.Find(_ => true).ToList();
            var books = Context.Books.Find(_ => true).ToEnumerable();

            //DangVH. Create. Start (02/11/2016)
            if (!string.IsNullOrEmpty(searchString))
            {
                books = books.Where(x => x.BookName.Contains(searchString) || x.Authors.Contains(searchString));
            }
            //DangVH. Create. End (02/11/2016)
            return(View(books));
        }
Beispiel #9
0
        //DangVH. Create. End (14/11/2016)


        //
        // GET: /Books/
        public ActionResult Index(string searchString, string currentFilter, int?page)
        {
            if (Context.Users.Find(x => x.Id.Equals(User.Identity.GetUserId())).FirstOrDefault().Roles.Contains("admin"))
            {
                //DangVH. Create. Start (02/11/2016)
                ViewBag.currentUser = Context.Users.Find(x => x.Id.Equals(new ObjectId(User.Identity.GetUserId()))).FirstOrDefault();
                ViewBag.bookNumber  = BooksControllerHelper.GetBookNumber();
                //DangVH. Create. End (02/11/2016)
                ViewBag.allCategories = BooksControllerHelper.ListAllCategory();
                ViewBag.allPublishers = Context.Publishers.Find(_ => true).ToList();
                ViewBag.allAuthors    = Context.Authors.Find(_ => true).ToList();
                var books = Context.Books.Find(x => x.Requested.Equals(false)).ToEnumerable();
                if (searchString != null)
                {
                    page = 1;
                }
                else
                {
                    searchString = currentFilter;
                }
                ViewBag.currentFilter = searchString;
                //DangVH. Create. Start (02/11/2016)
                if (!string.IsNullOrEmpty(searchString))
                {
                    var           authors       = Context.Authors.Find(_ => true).ToList().Where(x => x.AuthorName.Contains(searchString)).ToList();
                    List <string> searchAuthors = new List <string>();
                    foreach (var author in authors)
                    {
                        searchAuthors.Add(author.Id.ToString());
                    }
                    books = books.Where(x => x.BookName.Contains(searchString) || x.Authors.Intersect(searchAuthors).Any());
                }
                int pageSize   = 6;
                int pageNumber = (page ?? 1);
                //DangVH. Create. End (02/11/2016)
                return(View(books.ToPagedList(pageNumber, pageSize)));
            }
            else
            {
                ViewBag.errorMessage = "Bạn không có quyền truy cập vào chức năng này";
                return(View("NotFoundError"));
            }
        }
Beispiel #10
0
 //GET: /Books/BookRequest
 public ActionResult BookRequest(string searchString)
 {
     if (Context.Users.Find(x => x.Id.Equals(User.Identity.GetUserId())).FirstOrDefault().Roles.Contains("admin"))
     {
         var booksRequested = Context.Books.Find(x => x.Requested.Equals(true)).ToEnumerable();
         ViewBag.numberOfBook  = BooksControllerHelper.GetBookNumber();
         ViewBag.allCategories = Context.Categories.Find(_ => true).ToList();
         if (!string.IsNullOrEmpty(searchString))
         {
             booksRequested = booksRequested.Where(x => x.BookName.Contains(searchString) || x.RequestedBookAuthor.Contains(searchString));
         }
         return(View(booksRequested));
     }
     else
     {
         ViewBag.errorMessage = "Bạn không có quyền truy cập vào chức năng này";
         return(View("NotFoundError"));
     }
 }
Beispiel #11
0
        public ActionResult Create(Book book)
        {
            if (ModelState.IsValid)
            {
                // TODO: Add insert logic here
                //var selectedCategories = book.Categories.Where(x => x.IsSelected).Select(x => x.CategoryId).ToList();
                //DangVH. Create. Start (01/11/2016)
                var file         = Request.Files[0];
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                //DangVH. Create. End (01/11/2016)
                var addBook = new Book()
                {
                    BookName    = book.BookName,
                    Authors     = book.Authors,
                    ReleaseDay  = book.ReleaseDay.ToLocalTime(),
                    Description = book.Description,
                    ImgPublicId = uploadResult.PublicId
                };

                foreach (var publisherId in book.Publishers)
                {
                    addBook.Publishers.Add(publisherId);
                }

                foreach (var categoryId in book.Categories)
                {
                    addBook.Categories.Add(categoryId);
                }
                //foreach (var categoryId in selectedCategories)
                //{
                //    addBook.Categories.Add(new BookCategoriesViewModel()
                //    {
                //        CategoryId = categoryId
                //    });
                //}
                Context.Books.InsertOneAsync(addBook);
                return(RedirectToAction("Index"));
            }
            //Book newbook = BooksControllerHelper.GetCheckBoxValues();
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            return(View());
        }
Beispiel #12
0
        public ActionResult Edit(Book book)
        {
            if (ModelState.IsValid)
            {
                // TODO: Add update logic here
                //DangVH. Create. Start (02/11/2016)
                var file         = Request.Files[0];
                var uploadResult = ImageUploadHelper.GetUploadResult(file);
                //DangVH. Create. End (02/11/2016)
                //var selectedCategories = book.Categories.Where(x => x.IsSelected).Select(x => x.CategoryId).ToList();
                var editBook = Context.Books.Find(x => x.Id.Equals(new ObjectId(book.Id))).FirstOrDefault();
                editBook.BookName    = book.BookName;
                editBook.Authors     = book.Authors;
                editBook.ReleaseDay  = book.ReleaseDay.ToLocalTime();
                editBook.Description = book.Description;
                editBook.ImgPublicId = uploadResult.PublicId;
                editBook.Categories.Clear();
                editBook.Publishers.Clear();
                //foreach (var categoryId in selectedCategories)
                //{
                //    editBook.Categories.Add(new BookCategoriesViewModel()
                //    {
                //        CategoryId = categoryId
                //    });
                //}
                foreach (var publisherId in book.Publishers)
                {
                    editBook.Publishers.Add(publisherId);
                }

                foreach (var categoryId in book.Categories)
                {
                    editBook.Categories.Add(categoryId);
                }
                Context.Books.ReplaceOneAsync(x => x.Id.Equals(new ObjectId(book.Id)), editBook);
                return(RedirectToAction("Index"));
            }
            ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
            return(View());
        }
Beispiel #13
0
 public ActionResult Create(Book book)
 {
     if (Context.Users.Find(x => x.Id.Equals(User.Identity.GetUserId())).FirstOrDefault().Roles.Contains("admin"))
     {
         var listBook = Context.Books.Find(_ => true).ToList();
         var file     = Request.Files[0];
         if (file.ContentLength == 0)
         {
             ModelState.AddModelError("ImgPublicId", "Ảnh sách bắt buộc");
         }
         foreach (var eachBook in listBook)
         {
             if (book.BookName != null && eachBook.BookName.ToLower().Equals(book.BookName.ToLower()))
             {
                 ModelState.AddModelError("BookName", "Tên sách đã tồn tại");
             }
         }
         if (book.Authors.Count == 0)
         {
             ModelState.AddModelError("Authors", "Tác giả bắt buộc");
         }
         if (book.Categories.Count == 0)
         {
             ModelState.AddModelError("Categories", "Thể loại sách bắt buộc");
         }
         if (book.Publishers.Count == 0)
         {
             ModelState.AddModelError("Publishers", "Nhà xuất bản bắt buộc");
         }
         if (ModelState.IsValid)
         {
             var uploadResult = ImageUploadHelper.GetUploadResult(file);
             var addBook      = new Book()
             {
                 BookName    = book.BookName,
                 ReleaseDay  = book.ReleaseDay.ToLocalTime(),
                 Description = book.Description,
                 ImgPublicId = uploadResult.PublicId,
                 Requested   = false,
                 Text        = CommonHelper.SearchString(book.BookName.ToLower())
             };
             foreach (var publisherId in book.Publishers)
             {
                 addBook.Publishers.Add(publisherId);
             }
             foreach (var categoryId in book.Categories)
             {
                 addBook.Categories.Add(categoryId);
             }
             foreach (var authorId in book.Authors)
             {
                 addBook.Authors.Add(authorId);
             }
             //DangVH. Create. End (14/11/2016)
             Context.Books.InsertOneAsync(addBook);
             return(RedirectToAction("Index"));
         }
         //DangVH. Update. Start (14/11/2016)
         //Book newbook = BooksControllerHelper.GetCheckBoxValues();
         ViewBag.bookNumber = BooksControllerHelper.GetBookNumber();
         var selectedPublisherValue = book.Publishers.ToString();
         var selectedCategoryValue  = book.Categories.ToString();
         var selectedAuthorValue    = book.Authors.ToString();
         ViewBag.publisherId = GetPubsCatsAus(selectedPublisherValue.Split(','), 1);
         ViewBag.categoryId  = GetPubsCatsAus(selectedCategoryValue.Split(','), 2);
         ViewBag.authorId    = GetPubsCatsAus(selectedAuthorValue.Split(','), 3);
         //DangVH. Update. End (14/11/2016)
         return(View(book));
     }
     else
     {
         ViewBag.errorMessage = "Bạn không có quyền truy cập vào chức năng này";
         return(View("NotFoundError"));
     }
 }