Esempio n. 1
0
        public ActionResult Details(string id)
        {
            List <string> list = new List <string>();

            foreach (var x in ReportContentViewModel.EnumToList <ReportContentViewModel.ReportUser>())
            {
                list.Add(ReportContentViewModel.GetEnumDescription(x));
            }
            ViewBag.reportContentList = list;
            var allUser = Context.Users.Find(_ => true).ToList();

            if (allUser.Where(x => x.Id.Equals(id)).Any() == false)
            {
                ViewBag.errorMessage = "Không có kết quả!";
                return(View("NotFoundError"));
            }
            else
            {
                var user = Context.Users.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
                ViewBag.currentUser      = User.Identity.GetUserId();
                ViewBag.cloudinary       = cloudinary;
                ViewBag.allUser          = allUser;
                ViewBag.allBook          = Context.Books.Find(_ => true).ToList();
                ViewBag.allAuthor        = Context.Authors.Find(_ => true).ToList();
                ViewBag.listInteractBook = BooksControllerHelper.LastestBookInteracted(id);
                return(View(user));
            }
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
 //
 // GET: /Books/Create
 public ActionResult Create()
 {
     ViewBag.bookNumber  = BooksControllerHelper.GetBookNumber();
     ViewBag.CategoryId  = GetPubsCats(null, 2);
     ViewBag.PublisherId = GetPubsCats(null, 1);
     return(View());
 }
Esempio n. 4
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"));
     }
 }
Esempio n. 5
0
        public ActionResult Index()
        {
            List <Book> ListBook = Context.Books.AsQueryable <Book>().OrderByDescending(x => x.ReleaseDay).Take(4).ToList();
            //var userid = User.Identity.GetUserId();
            //ApplicationUser currentUser = UserManager.FindByIdAsync(userid);
            var user = UserManager.FindById(User.Identity.GetUserId());

            ViewBag.listHotBook = BooksControllerHelper.SuggestBook("", 1);
            ViewBag.listNewBook = BooksControllerHelper.SuggestBook("", 3);
            ViewBag.cloudinary  = cloudinary;
            var listGroup = new List <Group>();

            foreach (var group in Context.Groups.Find(_ => true).ToList())
            {
                foreach (var member in group.GroupMembers)
                {
                    if (member.UserId == User.Identity.GetUserId())
                    {
                        listGroup.Add(group);
                    }
                }
            }
            Random random = new Random((int)(DateTime.Now.Ticks));

            ViewBag.randomAuthor    = Context.Users.Find(_ => true).ToList().OrderBy(x => random.Next()).Take(2).ToList();
            ViewBag.randomPublisher = Context.Publishers.Find(_ => true).ToList().OrderBy(x => random.Next()).Take(2).ToList();
            ViewBag.listGroup       = listGroup;
            return(View(user));
        }
Esempio n. 6
0
        //
        // GET: /UserProfile/Edit/5
        public ActionResult EditProfile(string id)
        {
            var allUser = Context.Users.Find(_ => true).ToList();

            if (allUser.Where(x => x.Id.Equals(id)).Any() == false)
            {
                ViewBag.errorMessage = "Không có kết quả!";
                return(View("NotFoundError"));
            }
            else
            {
                var         user       = Context.Users.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
                UserProfile newprofile = new UserProfile()
                {
                    id       = user.Id,
                    UserName = user.UserName,
                    DOB      = Convert.ToDateTime(user.DOB).ToString("dd/MM/yyyy"),
                    Gender   = user.Gender,
                    Address  = user.Address
                };
                ViewBag.cloudinary       = cloudinary;
                ViewBag.user             = user;
                ViewBag.currentUser      = User.Identity.GetUserId();
                ViewBag.allUser          = allUser;
                ViewBag.allAuthor        = Context.Authors.Find(_ => true).ToList();
                ViewBag.listInteractBook = BooksControllerHelper.LastestBookInteracted(id);
                return(View(newprofile));
            }
        }
Esempio n. 7
0
        public ActionResult Index()
        {
            var user = UserManager.FindById(User.Identity.GetUserId());

            ViewBag.listHotBook = BooksControllerHelper.SuggestBook("", 1);
            ViewBag.listNewBook = BooksControllerHelper.SuggestBook("", 3);
            ViewBag.allUsers    = Context.Users.Find(_ => true).ToList();
            ViewBag.allAuthors  = Context.Authors.Find(_ => true).ToList();
            ViewBag.cloudinary  = cloudinary;
            var listGroup = new List <Group>();

            foreach (var group in Context.Groups.Find(_ => true).ToList())
            {
                foreach (var member in group.GroupMembers)
                {
                    if (member.UserId == User.Identity.GetUserId())
                    {
                        listGroup.Add(group);
                    }
                }
            }
            Random random = new Random((int)(DateTime.Now.Ticks));

            ViewBag.randomAuthor    = Context.Authors.Find(x => x.UserId != user.Id.ToString()).ToList().OrderBy(x => random.Next()).Take(2).ToList();
            ViewBag.randomPublisher = Context.Publishers.Find(_ => true).ToList().OrderBy(x => random.Next()).Take(2).ToList();
            ViewBag.listGroup       = listGroup;
            return(View(user));
        }
Esempio n. 8
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));
        }
Esempio n. 9
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));
        }
Esempio n. 10
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());
 }
Esempio n. 11
0
        public ActionResult LockedPage()
        {
            ViewBag.allAuthors = Context.Authors.Find(_ => true).ToList();
            ViewBag.cloudinary = cloudinary;
            var user = UserManager.FindById(User.Identity.GetUserId());

            ViewBag.listHotBook = BooksControllerHelper.SuggestBook("", 1);
            Random random = new Random((int)(DateTime.Now.Ticks));

            ViewBag.randomAuthor    = Context.Authors.Find(x => x.UserId != user.Id.ToString()).ToList().OrderBy(x => random.Next()).Take(2).ToList();
            ViewBag.randomPublisher = Context.Publishers.Find(_ => true).ToList().OrderBy(x => random.Next()).Take(2).ToList();
            return(View(user));
        }
Esempio n. 12
0
        public ActionResult RatingBook(string id, int rating)
        {
            var book        = Context.Books.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
            int ratingPoint = book.RatingPoint + rating;
            int ratingTime  = book.RateTime + 1;
            var filter      = Builders <Book> .Filter.Where(x => x.Id.Equals(book.Id));

            var update = Builders <Book> .Update.Set(x => x.RatingPoint, ratingPoint).
                         Set(x => x.RateTime, ratingTime).
                         Set(x => x.AvarageRating, BooksControllerHelper.GetAverageRatingPoint(ratingPoint, ratingTime));

            Context.Books.UpdateOneAsync(filter, update);
            return(Json("Cảm ơn bạn đã đánh giá :D"));
        }
Esempio n. 13
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));
        }
Esempio n. 14
0
        //
        // GET: /Books/Details/5
        public ActionResult Details(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();

            foreach (var comment in book.Comments)
            {
                comment.LinesDescription = comment.Description.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
            }
            book.Comments = book.Comments.OrderByDescending(x => x.CreatedTime).ToList();
            Console.Write(book);
            var allCategory = Context.Categories.Find(_ => true).ToEnumerable();

            ViewBag.allCategories      = BooksControllerHelper.ListAllCategory();
            ViewBag.allPublishers      = Context.Publishers.Find(_ => true).ToList();
            ViewBag.avarageRatingPoint = BooksControllerHelper.GetAverageRatingPoint(book.RatingPoint, book.RateTime);
            var booksStatistic = Context.BooksStatistic.Find(_ => true).ToList();
            var date           = DateTime.Now;
            var builder        = Builders <BookStatistic> .Filter;
            var filter         = builder.Eq("BookId", book.Id) & builder.Eq("EachDate", date.Date.AddHours(7));

            if (Context.BooksStatistic.Find(filter).FirstOrDefault() != null)
            {
                int count  = Context.BooksStatistic.Find(filter).FirstOrDefault().Count + 1;
                var update = Builders <BookStatistic> .Update.Set(x => x.Count, count);

                Context.BooksStatistic.UpdateOneAsync(filter, update);
            }
            else
            {
                var bookStatistic = new BookStatistic()
                {
                    BookId   = book.Id,
                    EachDate = date.Date.AddHours(7)
                };
                Context.BooksStatistic.InsertOneAsync(bookStatistic);
            }
            ViewBag.listSameBook = BooksControllerHelper.SuggestBook(id, 4);
            Random random = new Random((int)(DateTime.Now.Ticks));

            ViewBag.randomGroup = Context.Groups.Find(_ => true).ToList().OrderBy(x => random.Next()).Take(4).ToList();
            ViewBag.currentUser = Context.Users.Find(x => x.Id.Equals(new ObjectId(User.Identity.GetUserId()))).FirstOrDefault();
            ViewBag.allUser     = Context.Users.Find(_ => true).ToList();
            return(View(book));
        }
Esempio n. 15
0
        public async Task <ActionResult> EditProfile(UserProfile user1)
        {
            var allUser = Context.Users.Find(_ => true).ToList();

            if (user1.UserName != null)
            {
                foreach (var user in allUser)
                {
                    if (user.UserName.ToLower().Equals(user1.UserName.ToLower()) &&
                        allUser.Find(x => x.UserName.ToLower().Equals(user1.UserName.ToLower())).Id != user1.id)
                    {
                        ModelState.AddModelError("UserName", "Tên đã tồn tại");
                    }
                }
            }
            if (user1.DOB == null)
            {
                ModelState.AddModelError("DOB", "Ngày sinh không được để trống");
            }
            if (ModelState.IsValid)
            {
                var user2 = await UserManager.FindByIdAsync(user1.id);

                if (user2 == null)
                {
                    return(HttpNotFound());
                }

                user2.Address  = user1.Address;
                user2.DOB      = DateTime.ParseExact(user1.DOB, "dd/MM/yyyy", CultureInfo.InvariantCulture).AddHours(7);
                user2.Gender   = user1.Gender;
                user2.UserName = user1.UserName;
                user2.Text     = CommonHelper.SearchString(user1.UserName.ToLower());
                await Context.Users.ReplaceOneAsync(x => x.Id.Equals(new ObjectId(user2.Id)), user2);

                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.cloudinary       = cloudinary;
            ViewBag.user             = Context.Users.Find(x => x.Id.Equals(new ObjectId(user1.id))).FirstOrDefault();
            ViewBag.currentUser      = User.Identity.GetUserId();
            ViewBag.allUser          = allUser;
            ViewBag.allAuthor        = Context.Authors.Find(_ => true).ToList();
            ViewBag.listInteractBook = BooksControllerHelper.LastestBookInteracted(user1.id);
            return(View(user1));
        }
Esempio n. 16
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));
        }
Esempio n. 17
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"));
     }
 }
Esempio n. 18
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"));
            }
        }
Esempio n. 19
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());
        }
Esempio n. 20
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());
        }
Esempio n. 21
0
 //
 // GET: /Groups/id/MainPage/
 public ActionResult MainPage(string id)
 {
     {
         var allGroup = Context.Groups.Find(_ => true).ToList();
         if (allGroup.Where(x => x.Id.Equals(id)).Any() == false)
         {
             ViewBag.errorMessage = "Không có kết quả!";
             return(View("NotFoundError"));
         }
         else
         {
             var group = Context.Groups.Find(x => x.Id.Equals(new ObjectId(id))).FirstOrDefault();
             if (group.Locked == true)
             {
                 return(RedirectToAction("LockedPage", "Home"));
             }
             else
             {
                 ViewBag.cloudinary = cloudinary;
                 var currentUser = User.Identity.GetUserId();
                 ViewBag.currentUser = currentUser;
                 var listGroupOfUser = new List <Group>();
                 foreach (var grp in allGroup)
                 {
                     if (grp.GroupMembers.Find(x => x.UserId.Equals(currentUser)) != null)
                     {
                         listGroupOfUser.Add(grp);
                     }
                 }
                 ViewBag.listGroupOfUser  = listGroupOfUser;
                 ViewBag.allUser          = Context.Users.Find(_ => true).ToList();
                 ViewBag.groupReport      = GroupReportContent();
                 ViewBag.allAuthor        = Context.Authors.Find(_ => true).ToList();
                 ViewBag.listInteractBook = BooksControllerHelper.LastestBookInteracted(User.Identity.GetUserId());
                 return(View(group));
             }
         }
     }
 }
Esempio n. 22
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"));
     }
 }
Esempio n. 23
0
        //
        // GET: /Books/Details/5
        public ActionResult Details(string id)
        {
            //DangVH. Create. Start (02/11/2016)
            ViewBag.cloudinary = cloudinary;
            //DangVH. Create. End (02/11/2016)
            var allBook = Context.Books.Find(_ => true).ToList();
            var check   = allBook.Where(x => x.Id.Equals(id)).Any();

            if (check == 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();
                foreach (var comment in book.Comments)
                {
                    comment.LinesDescription = comment.Description.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
                }
                book.Comments = book.Comments.OrderByDescending(x => x.CreatedTime).ToList();
                Console.Write(book);
                var allCategory = Context.Categories.Find(_ => true).ToEnumerable();
                ViewBag.allCategories      = BooksControllerHelper.ListAllCategory();
                ViewBag.allPublishers      = Context.Publishers.Find(_ => true).ToList();
                ViewBag.avarageRatingPoint = BooksControllerHelper.GetAverageRatingPoint(book.RatingPoint, book.RateTime);
                // Đoạn này để tính số lượt truy cập của sách
                var booksStatistic = Context.BooksStatistic.Find(_ => true).ToList();
                var date           = DateTime.Now;
                var builder        = Builders <BookStatistic> .Filter;
                var filter         = builder.Eq("BookId", book.Id) & builder.Eq("EachDate", date.Date.AddHours(7));
                if (Context.BooksStatistic.Find(filter).FirstOrDefault() != null)
                {
                    int count  = Context.BooksStatistic.Find(filter).FirstOrDefault().Count + 1;
                    var update = Builders <BookStatistic> .Update.Set(x => x.Count, count);

                    Context.BooksStatistic.UpdateOneAsync(filter, update);
                }
                else
                {
                    var bookStatistic = new BookStatistic()
                    {
                        BookId   = book.Id,
                        EachDate = date.Date.AddHours(7)
                    };
                    Context.BooksStatistic.InsertOneAsync(bookStatistic);
                }
                // Hết đoạn tính số lượt truy cập sách
                // Xử lý sách đã xem và đánh giá gần đây của người dùng hiện tại
                var userInteractFilter = Builders <ApplicationUser> .Filter.Where(x => x.Id.Equals(User.Identity.GetUserId()));

                var userInteractUpdate = Builders <ApplicationUser> .Update.Push(x => x.Interacbook, new InteractBookViewModel
                {
                    Id           = ObjectId.GenerateNewId(),
                    BookId       = book.Id,
                    InteractTime = DateTime.Now.AddHours(7)
                });

                Context.Users.UpdateOneAsync(userInteractFilter, userInteractUpdate);
                // Hết phần xử lí sách đã xem và đánh giá gần đây của người dùng hiện tại
                ViewBag.listSameBook = BooksControllerHelper.SuggestBook(id, 4);                                            // Lấy list sách có chung thể loại
                Random random = new Random((int)(DateTime.Now.Ticks));
                ViewBag.randomGroup = Context.Groups.Find(_ => true).ToList().OrderBy(x => random.Next()).Take(4).ToList(); // List nhóm ngẫu nhiên
                ViewBag.listGroupHaveTagIsCurrentBook = GroupsControllerHelper.SuggestGroup(id);                            // List nhóm có thẻ là sách hiện tại
                ViewBag.allAuthor = Context.Authors.Find(_ => true).ToList();
                ViewBag.allUser   = Context.Users.Find(_ => true).ToList();
                return(View(book));
            }
        }