public ViewResult Take(int id)
        {
            ThemesListViewModel model = new ThemesListViewModel
            {
                Themes = repository.Themes
            };
            string title = "";

            foreach (var t in model.Themes)
            {
                if (id == t.Id)
                {
                    title = t.Title;
                }
            }
            //Theme modelone = new Theme
            //{
            //    Title = title
            //};
            Article modelone = new Article
            {
                Title = title
            };

            return(View(modelone));
        }
Exemple #2
0
        public void Can_Send_Pagination_View_Model()
        {
            Mock <IThemeRepository> mock = new Mock <IThemeRepository>();

            mock.Setup(m => m.Themes).Returns(new List <Theme>
            {
                new Theme {
                    Id = 1, Title = "theme 1", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 2, Title = "theme 2", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 3, Title = "theme 3", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 4, Title = "theme 4", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 5, Title = "theme 5", Description = "Good", Teacher = ""
                },
            });

            ThemesController controller = new ThemesController(mock.Object);

            controller.pageSize = 3;

            ThemesListViewModel result  = (ThemesListViewModel)controller.List(2).Model;
            PagingInfo          pagInfo = result.PagingInfo;

            Assert.AreEqual(pagInfo.CurrentPage, 2);
            Assert.AreEqual(pagInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagInfo.TotalItems, 5);
            Assert.AreEqual(pagInfo.TotalPages, 2);
        }
        public ViewResult List()
        {
            ThemesListViewModel themesList = new ThemesListViewModel();

            themesList.themes       = iThemes.Themes;
            themesList.currentLevel = "Начинающий";
            return(View(themesList));
        }
Exemple #4
0
        public void Can_Paginate()
        {
            //органызація
            Mock <IThemeRepository> mock = new Mock <IThemeRepository>();

            mock.Setup(m => m.Themes).Returns(new List <Theme>
            {
                new Theme {
                    Id = 1, Title = "theme 1", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 2, Title = "theme 2", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 3, Title = "theme 3", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 4, Title = "theme 4", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 5, Title = "theme 5", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 6, Title = "theme 6", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 7, Title = "theme 7", Description = "Good", Teacher = ""
                },
                new Theme {
                    Id = 8, Title = "theme 8", Description = "Good", Teacher = ""
                }
            });

            ThemesController controller = new ThemesController(mock.Object);

            controller.pageSize = 3;

            //Дія
            ThemesListViewModel result = (ThemesListViewModel)controller.List(3).Model;

            //Ствердження
            List <Theme> themes = result.Themes.ToList();

            Assert.IsTrue(themes.Count == 2);
            Assert.AreEqual(themes[0].Title, "theme 7");
            Assert.AreEqual(themes[1].Title, "theme 8");
        }
        public ViewResult List(int page = 1)
        {
            ThemesListViewModel model = new ThemesListViewModel
            {
                Themes = repository.Themes
                         .OrderBy(theme => theme.Id)
                         .Skip((page - 1) * pageSize)
                         .Take(pageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                    TotalItems   = repository.Themes.Count()
                }
            };

            return(View(model));
        }