Exemplo n.º 1
0
 public static int GetBookNumber()
 {
     return((int)BooksControllerHelper.Context().Books.Find(_ => true).Count());
 }
Exemplo n.º 2
0
        //public static Models.Book GetCheckBoxValues()
        //{
        //    ApplicationIdentityContext Context = ApplicationIdentityContext.Create();
        //    Book book = new Book();
        //    var allCategory = Context.Categories.Find(_ => true).ToEnumerable();
        //    var bookCategoriesViewModel = new List<BookCategoriesViewModel>();
        //    foreach (var category in allCategory)
        //    {
        //        bookCategoriesViewModel.Add(new BookCategoriesViewModel()
        //        {
        //            CategoryId = category.Id,
        //            CategoryName = category.CategoryName,
        //            IsSelected = false
        //        });
        //    }
        //    book.Categories = bookCategoriesViewModel;
        //    return book;
        //}

        public static List <BooksSuggestViewModel> SuggestBook(string bookId, int option)
        {
            var         Context  = BooksControllerHelper.Context();
            List <Book> listBook = Context.Books.Find(_ => true).ToList();
            List <BooksSuggestViewModel> suggestBooks = new List <BooksSuggestViewModel>();

            switch (option)
            {
            case 1:
                DateTime startTime = DateTime.Now.AddDays(-1);
                DateTime endTime   = DateTime.Now;
                List <BooksSuggestViewModel> newList = new List <BooksSuggestViewModel>();
                var b = Context.BooksStatistic.Find(x => x.EachDate.Equals(startTime.Date.AddHours(7))).ToList();
                var c = Context.BooksStatistic.Find(x => x.EachDate.Equals(endTime.Date.AddHours(7))).ToList();
                if (b.Count() == 0)
                {
                    foreach (var c1 in c)
                    {
                        newList.Add(new BooksSuggestViewModel()
                        {
                            BookId      = c1.BookId,
                            Count       = c1.Count,
                            BookName    = listBook.Find(x => x.Id.Equals(c1.BookId)).BookName,
                            AuthorName  = listBook.Find(x => x.Id.Equals(c1.BookId)).Authors,
                            ImgPublicId = listBook.Find(x => x.Id.Equals(c1.BookId)).ImgPublicId,
                            RateTime    = listBook.Find(x => x.Id.Equals(c1.BookId)).RateTime
                        });
                    }
                }
                else
                {
                    foreach (var b1 in b)
                    {
                        foreach (var c1 in c)
                        {
                            if (b1.BookId == c1.BookId)
                            {
                                newList.Add(new BooksSuggestViewModel()
                                {
                                    BookId      = b1.BookId,
                                    Count       = b1.Count + c1.Count,
                                    BookName    = listBook.Find(x => x.Id.Equals(c1.BookId)).BookName,
                                    AuthorName  = listBook.Find(x => x.Id.Equals(c1.BookId)).Authors,
                                    ImgPublicId = listBook.Find(x => x.Id.Equals(c1.BookId)).ImgPublicId,
                                    RateTime    = listBook.Find(x => x.Id.Equals(c1.BookId)).RateTime
                                });
                            }
                            else
                            {
                                newList.Add(new BooksSuggestViewModel()
                                {
                                    BookId      = b1.BookId,
                                    Count       = b1.Count,
                                    BookName    = listBook.Find(x => x.Id.Equals(b1.BookId)).BookName,
                                    AuthorName  = listBook.Find(x => x.Id.Equals(b1.BookId)).Authors,
                                    ImgPublicId = listBook.Find(x => x.Id.Equals(b1.BookId)).ImgPublicId,
                                    RateTime    = listBook.Find(x => x.Id.Equals(b1.BookId)).RateTime
                                });
                            }
                        }
                    }
                }
                suggestBooks = newList.OrderByDescending(x => x.Count).ToList();
                suggestBooks = suggestBooks.GroupBy(x => x.BookId).Select(y => y.First()).ToList().Take(4).ToList();
                Console.Write(suggestBooks);
                break;

            case 2:
                listBook = listBook.OrderByDescending(x => x.AvarageRating).Take(4).ToList();
                foreach (var book in listBook)
                {
                    suggestBooks.Add(new BooksSuggestViewModel()
                    {
                        BookId      = book.Id,
                        BookName    = book.BookName,
                        AuthorName  = book.Authors,
                        ImgPublicId = book.ImgPublicId,
                        RateTime    = book.RateTime
                    });
                }
                break;

            case 3:
                listBook = listBook.OrderByDescending(x => x.ReleaseDay).Take(4).ToList();
                foreach (var book in listBook)
                {
                    suggestBooks.Add(new BooksSuggestViewModel()
                    {
                        BookId      = book.Id,
                        BookName    = book.BookName,
                        AuthorName  = book.Authors,
                        ImgPublicId = book.ImgPublicId,
                        RateTime    = book.RateTime
                    });
                }
                break;

            case 4:
                var modelBook = Context.Books.Find(x => x.Id.Equals(new ObjectId(bookId))).FirstOrDefault();
                foreach (var book in listBook)
                {
                    int count = 0;
                    foreach (var category in modelBook.Categories)
                    {
                        if (book.Categories.Contains(category) && !book.Id.Equals(new ObjectId(bookId)))
                        {
                            count = count + 1;
                        }
                    }
                    if (book.Id != bookId)
                    {
                        suggestBooks.Add(new BooksSuggestViewModel()
                        {
                            BookId      = book.Id,
                            BookName    = book.BookName,
                            AuthorName  = book.Authors,
                            ImgPublicId = book.ImgPublicId,
                            RateTime    = book.RateTime,
                            Count       = count
                        });
                    }
                }
                Console.Write(suggestBooks);
                suggestBooks = suggestBooks.OrderByDescending(x => x.Count).Take(4).ToList();
                break;
            }
            //return suggestBooks;
            return(suggestBooks);
        }
Exemplo n.º 3
0
 public static int GetBookNumber()
 {
     return((int)BooksControllerHelper.Context().Books.Find(x => x.Requested.Equals(false)).Count());
 }