public ActionResult Selected(int id = 1)
        {
            var currentNews = this.Data.News.GetById(id);

            if (currentNews == null || currentNews.IsDeleted)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, Resource.Views.Selected.Invalid_news_id);
            }

            var previousNews = this.Data.News.All()
                .OrderByDescending(x => x.Id)
                .Where(x => x.Id < currentNews.Id && x.IsVisible && !x.IsDeleted)
                .FirstOrDefault();

            if (previousNews == null)
            {
                previousNews = this.Data.News.All()
                    .OrderByDescending(x => x.Id)
                    .Where(x => x.IsVisible && !x.IsDeleted)
                    .First();
            }

            var nextNews = this.Data.News.All()
                .OrderBy(x => x.Id)
                .Where(x => x.Id > currentNews.Id && x.IsVisible && !x.IsDeleted)
                .FirstOrDefault();

            if (nextNews == null)
            {
                nextNews = this.Data.News.All()
                    .OrderBy(x => x.Id)
                    .Where(x => x.IsVisible && !x.IsDeleted)
                    .First();
            }

            var newsContentViewModel = new SelectedNewsViewModel
            {
                Id = currentNews.Id,
                Title = currentNews.Title,
                Author = currentNews.Author,
                Source = currentNews.Source,
                TimeCreated = currentNews.CreatedOn,
                Content = currentNews.Content,
                PreviousId = previousNews.Id,
                NextId = nextNews.Id
            };

            return this.View(newsContentViewModel);
        }
Пример #2
0
        public ActionResult Selected(int id = 1)
        {
            var currentNews = this.Data.News.GetById(id);

            if (currentNews == null || currentNews.IsDeleted)
            {
                this.TempData.Add("InfoMessage", "Невалидна новина.");
                return this.View();
            }

            var previousNews = this.Data.News.All()
                .OrderByDescending(x => x.Id)
                .Where(x => x.Id < currentNews.Id && x.IsVisible && !x.IsDeleted)
                .FirstOrDefault();

            if (previousNews == null)
            {
                previousNews = this.Data.News.All()
                    .OrderByDescending(x => x.Id)
                    .Where(x => x.IsVisible && !x.IsDeleted)
                    .First();
            }

            var nextNews = this.Data.News.All()
                .OrderBy(x => x.Id)
                .Where(x => x.Id > currentNews.Id && x.IsVisible && !x.IsDeleted)
                .FirstOrDefault();

            if (nextNews == null)
            {
                nextNews = this.Data.News.All()
                    .OrderBy(x => x.Id)
                    .Where(x => x.IsVisible && !x.IsDeleted)
                    .First();
            }

            var newsContentViewModel = new SelectedNewsViewModel
            {
                Id = currentNews.Id,
                Title = currentNews.Title,
                Author = currentNews.Author,
                Source = currentNews.Source,
                TimeCreated = currentNews.CreatedOn,
                Content = currentNews.Content,
                PreviousId = previousNews.Id,
                NextId = nextNews.Id
            };

            return this.View(newsContentViewModel);
        }