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)); }
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)); }
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)); }
// // 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)); }
// // 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)); } }