コード例 #1
0
        public ActionResult Index()
        {
            var topArticles = Data.Articles.All()
                              .Where(article => article.IsSelectedForTopArticle)
                              .Select(ArticleViewModel.FromArticle(CurrentCulture)).ToList();

            return(View(topArticles));
        }
コード例 #2
0
        public void FromArticle_MustReturnEmptyListIfNoArticlesAreSelectedForTopArticles()
        {
            IList <ArticleViewModel> models = _articles.AsQueryable().Select(ArticleViewModel
                                                                             .FromArticle(Culture.en.ToString())).ToList();

            Assert.AreEqual(models[0].Name, _articles[0].NameEn);
            Assert.AreEqual(models[0].Description, _articles[0].DescriptionEn);
            Assert.AreEqual(models[1].Name, _articles[1].NameEn);
            Assert.AreEqual(models[1].Description, _articles[1].DescriptionEn);
        }
コード例 #3
0
        public void FromArticle_AllReturnedArticlesMustHaveBgPropertiesIfCultureIsBg()
        {
            IList <ArticleViewModel> models = _articles.AsQueryable().Select(ArticleViewModel
                                                                             .FromArticle(Culture.bg.ToString())).ToList();

            Assert.AreEqual(models[0].Name, _articles[0].NameBg);
            Assert.AreEqual(models[0].Description, _articles[0].DescriptionBg);
            Assert.AreEqual(models[1].Name, _articles[1].NameBg);
            Assert.AreEqual(models[1].Description, _articles[1].DescriptionBg);
        }
コード例 #4
0
        public ActionResult Detail(int?articleId)
        {
            if (articleId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var article = Data.Articles.All().Select(ArticleViewModel.FromArticle(CurrentCulture))
                          .FirstOrDefault(a => a.Id == articleId);

            if (article == null)
            {
                return(HttpNotFound());
            }

            return(View(article));
        }
コード例 #5
0
        public ActionResult SearchResults(SearchArticlesViewModel searchModel)
        {
            if (searchModel.FromPrice != null && searchModel.ToPrice != null)
            {
                if (searchModel.FromPrice >= searchModel.ToPrice)
                {
                    ModelState.AddModelError("ToPrice", Errors.GreaterThan);

                    return(View("SearchArticles", searchModel));
                }
            }

            var articles = SearchByCriterias(searchModel);

            if (searchModel.PageNumber == 0)
            {
                searchModel.PageNumber = 1;
            }

            var numberOfPages = Math.Ceiling((double)articles.Count() / PageSize);

            var articlesToDisplay = articles
                                    .OrderBy(article => article.Price)
                                    .Select(ArticleViewModel.FromArticle(CurrentCulture))
                                    .Skip((searchModel.PageNumber - 1) * PageSize).Take(PageSize).ToList();

            if (articlesToDisplay.Count == 0)
            {
                return(RedirectToAction("SearchArticles")
                       .WithInfo(Labels.NoArticlesFound));
            }

            ViewBag.FromPrice       = searchModel.FromPrice;
            ViewBag.ToPrice         = searchModel.ToPrice;
            ViewBag.CategoryId      = searchModel.CategoryId;
            ViewBag.SearchSubstirng = searchModel.SearchSubstring;
            ViewBag.Pages           = numberOfPages;
            ViewBag.PageNumber      = searchModel.PageNumber;

            return(View(articlesToDisplay));
        }
コード例 #6
0
        public ActionResult ArticlesFromCategory(int?id, int?page)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            int pageNumber;

            if (page == 0)
            {
                pageNumber = 1;
            }
            else
            {
                pageNumber = page.GetValueOrDefault(1);
            }

            var articles = Data.Articles.All().Where(article => article.CateoryId == id);

            //We check if the user gave us incorrect category id
            if (articles.Count() == 0)
            {
                CheckIfCategoryExists((int)id);
            }

            var numberOfPages = Math.Ceiling((double)articles.Count() / PageSize);

            var articlesToDisplay = articles
                                    .OrderBy(article => article.Price)
                                    .Select(ArticleViewModel.FromArticle(CurrentCulture))
                                    .Skip((pageNumber - 1) * PageSize).Take(PageSize).ToList();

            ViewBag.CategoryId = id;
            ViewBag.Pages      = numberOfPages;
            ViewBag.PageNumber = pageNumber;

            return(View(articlesToDisplay));
        }