예제 #1
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));
        }
예제 #2
0
        // CONSTRUCTORS
        private UnitOfWork()
        {
            dataBaseContext = new DataBaseContext();

            authorRepositories     = null;
            abonnementRepository   = null;
            bookRepository         = null;
            categoryRepository     = null;
            genreRepository        = null;
            publishHouseRepository = null;
            readerRepository       = null;

            abonnementStatistic      = null;
            authorStatistic          = null;
            bookStatistic            = null;
            categoryStatistic        = null;
            genreStatistic           = null;
            publishingHouseStatistic = null;
            readerStatistic          = null;
        }
예제 #3
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));
            }
        }