示例#1
0
        public ActionResult Index()
        {
            var authorBO   = DependencyResolver.Current.GetService <AuthorBO>();
            var authorList = authorBO.GetAuthorsList().OrderBy(n => n.LastName);

            ViewBag.Authors = authorList.Select(x => mapper.Map <AuthorView>(x)).ToList();

            List <AuthorView> topAuthor = new List <AuthorView>();
            BookBO            books     = DependencyResolver.Current.GetService <BookBO>();
            var expensive = books.GetBooksList().Select(item => mapper.Map <BookView>(item)).OrderByDescending(b => b.Price).ToList();

            foreach (var item in expensive)
            {
                topAuthor.Add(authorList.Select(a => mapper.Map <AuthorView>(a)).Where(a => a.Id == item.AuthorId).FirstOrDefault());
            }


            ViewBag.AuthorsTop = topAuthor.Distinct().Take(5);

            return(View());
        }
        public ActionResult Index()
        {
            var authorBO   = DependencyResolver.Current.GetService <AuthorBO>();
            var authorList = authorBO.GetAuthorsList().OrderBy(n => n.LastName); //сортировка по фамилии в алфавитном порядке

            ViewBag.Authors = authorList.Select(a => mapper.Map <AuthorViewModel>(a)).ToList();

            List <AuthorViewModel> authorsTop = new List <AuthorViewModel>();
            BookBO booksBO = DependencyResolver.Current.GetService <BookBO>();

            //топ 5 авторов
            var expensiveBooks = booksBO.GetBooksList().OrderByDescending(b => b.Price).Select(x => mapper.Map <BookViewModel>(x)).ToList();

            expensiveBooks.ForEach(
                x =>
            {
                authorsTop.Add(authorList.Select(m => mapper.Map <AuthorViewModel>(m)).Where(a => a.Id == x.AuthorId).FirstOrDefault());
            });
            ViewBag.ListTopAuthors = authorsTop.Distinct().Take(5);

            return(View());
        }