コード例 #1
0
        public ActionResult List(string category, int page = 1)
        {
            NewsListViewModel model = new NewsListViewModel
            {
                News = repository.News
                       .Where(n => category == null || n.Category.Name == category)
                       .OrderBy(n => n.Created)
                       .Skip((page - 1) * Pagesize)
                       .Take(Pagesize),


                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = Pagesize,
                    TotalItems   = category == null?repository.News.Count() :
                                       repository.News.Where(e => e.Category.Name == category).Count()
                },

                // Categories = repository.ActualCategories.ToList(),
                CurrentCategory = category
            };

            return(View(model));
        }
コード例 #2
0
ファイル: NewsController.cs プロジェクト: BorislavKolev/TAK
        public IActionResult All(string searchString, int page = 1)
        {
            this.ViewData["CurrentSearchString"] = searchString;

            var viewModel = new NewsListViewModel();

            var count = this.newsService.GetNewsCount();

            viewModel.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage);
            var news = this.newsService.GetAll <NewsListItemViewModel>(ItemsPerPage, (page - 1) * ItemsPerPage);

            if (viewModel.PagesCount == 0)
            {
                viewModel.PagesCount = 1;
            }

            if (!string.IsNullOrEmpty(searchString))
            {
                news = news.Where(n => n.Title.ToLower().Contains(searchString.ToLower()) || n.Content.ToLower().Contains(searchString.ToLower()));
            }

            viewModel.News = news;

            viewModel.CurrentPage = page;

            return(this.View(viewModel));
        }
コード例 #3
0
        public IActionResult Index(int id, int category)
        {
            var list             = new NewsListViewModel();
            var news             = context.News.OrderByDescending(x => x.Written);
            var comments         = context.Comments.Include(x => x.News);
            var hasCategories    = context.HasCategories.Include(x => x.News).Include(x => x.Category);
            var newsWithCategory = hasCategories.Where(y => y.CategoryId == category)
                                   .Select(d => d.News)
                                   .OrderByDescending(x => x.Id);;
            var categories = context.Categories;

            foreach (var cat in categories)
            {
                list.Categories.Add(new CategoryViewModel()
                {
                    Category = cat,
                    Count    = hasCategories.Where(x => x.CategoryId == cat.Id).Count()
                });
            }

            if (id == 0)
            {
                id = 1;
            }
            int skip = (id - 1) * MaxDisplayedNews;

            var raw = (category == 0) ? news : newsWithCategory;

            if (raw.Count() > skip)
            {
                var test = raw.Count();
                var data = (raw.Count() - skip >= MaxDisplayedNews) ?
                           raw.Skip(skip).Take(MaxDisplayedNews) :
                           raw.Skip(skip);

                list.Pages = raw.Count() % MaxDisplayedNews > 0 ?
                             (raw.Count() / MaxDisplayedNews) + 1 :
                             raw.Count() / MaxDisplayedNews;

                foreach (var entry in data)
                {
                    var model = new NewsViewModel()
                    {
                        NewsId  = entry.Id,
                        Title   = entry.Title,
                        Written = entry.Written,
                        Author  = entry.Author,
                        Body    = entry.Body.Length >= MaxBodyDigits ?
                                  (entry.Body.Substring(0, MaxBodyDigits) + ToBeContinued) :
                                  entry.Body.ToString(),
                        ImageUrl     = entry.ImageUrl,
                        Categories   = hasCategories.Where(x => x.NewsId == entry.Id).Select(y => y.Category).ToList(),
                        CommentCount = comments.Where(y => y.News.Id == entry.Id).Count()
                    };

                    list.News.Add(model);
                }
            }
            return(View(list));
        }
コード例 #4
0
        public NewsListViewModel GetNewsListViewModel(int?page, int?pagesize, string category = null)
        {
            int pageIndex = 0;

            if (page > 0)
            {
                pageIndex = page.Value - 1;
            }
            var pageSize = pagesize.GetValueOrDefault(10);

            var records = GetManyNewsItemViewModel(category).ToList();

            var list  = new PagedList <NewsItemViewModel>(records, pageIndex, pageSize);
            var model = new NewsListViewModel
            {
                CategoryId = category,
                News       = list,
                PagerModel = new PagerViewModel
                {
                    PageSize     = list.PageSize,
                    TotalRecords = list.TotalCount,
                    PageIndex    = list.PageIndex,
                    RouteValues  = new RouteValues {
                        page = pageIndex, category = category
                    },
                }
            };

            return(model);
        }
コード例 #5
0
        private void PopulateCategories(NewsListViewModel model, List <string> filters, Item parentItem, string queryFilter)
        {
            if (filters == null)
            {
                filters = new List <string>();
            }
            var articleTags = parentItem[Templates.NewsTaxonomy.Fields.Category]?.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) ?? new List <string>().ToArray();

            foreach (string tag in articleTags)
            {
                var tagItem = context.Database.GetItem(tag);
                if (tagItem == null)
                {
                    continue;
                }

                var tagModel = new NewsFilterItem();
                tagModel.ID       = tagItem.ID.ToString();
                tagModel.Name     = tagItem[Templates.Taxonomy.Fields.Title];
                tagModel.Key      = Regex.Replace(tagModel.Name, @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                tagModel.Selected = filters.Contains(tagModel.ID) || tagModel.Key.Equals(queryFilter, StringComparison.OrdinalIgnoreCase);
                if (tagModel.Selected && !filters.Contains(tagModel.ID))
                {
                    filters.Add(tag);
                }
                model.Tags.Add(tagModel);
            }
        }
コード例 #6
0
        // GET: News
        public ActionResult Index()
        {
            var newsListQuery = _newsService.GetRepoNewsList();
            //IEnumerable<dynamic> newsList = from news in newsListQuery
            //                                select Shape.News
            //                              (
            //                                  id: news.Id,
            //                                  newsTitle: news.NewsTitle,
            //                                  newsContent: news.NewsContent,
            //                                  newsCategory: news.NewsCategory
            //                              );
            //NewsListViewModel model = new NewsListViewModel(newsList);

            var newspartListQuery = _newsService.GetNewsList().List();
            IEnumerable <dynamic> newspartList = from a in newspartListQuery
                                                 select Shape.News
                                                 (
                id : a.Id,
                newsTitle : a.NewsTitle,
                newsContent : a.NewsContent,
                newsCategory : a.NewsCategory
                                                 );

            NewsListViewModel model = new NewsListViewModel(newspartList);

            return(View(model));
        }
コード例 #7
0
        public IActionResult List()
        {
            var vm = new NewsListViewModel();

            if (TempData.ContainsKey(TEMP_NEWS_SEARCH_KEY))
            {
                MergeToModelState(vm);
                var tempdata       = TempData.Get <NewsSearchCondition>(TEMP_NEWS_SEARCH_KEY);
                var successMessage = TempData.Get <string>(TEMP_NEWS_SUCCESS_KEY);
                if (successMessage != null)
                {
                    vm = new NewsListViewModel {
                        SearchCondition = tempdata, SuccessMessage = successMessage
                    };
                }
                else
                {
                    vm = new NewsListViewModel {
                        SearchCondition = tempdata
                    };
                    MergeToModelState(vm);
                }
            }
            TempData.Clear();
            return(View(vm));
        }
コード例 #8
0
        public ActionResult Index(NewsListPage currentPage)
        {
            var pageSize = 5;

            var model = new NewsListViewModel(currentPage);

            var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>();

            var newsItems = contentLoader.GetChildren <NewsPage>(currentPage.ContentLink)
                            .OrderByDescending(n => n.Created);

            model.TotalArticles = newsItems.Count();
            model.TotalPages    = Math.Ceiling(model.TotalArticles / (double)pageSize);

            var q = Request.QueryString;
            int p;

            if (string.IsNullOrEmpty(q["p"]) || !int.TryParse(q["p"], out p) || p <= 1)
            {
                model.CurrentPageNumber = 1;
                model.Articles          = newsItems.Take(pageSize);
            }
            else
            {
                model.CurrentPageNumber = p;
                model.Articles          = newsItems.Skip((p - 1) * pageSize).Take(pageSize);
            }

            return(View(model));
        }
コード例 #9
0
        public ActionResult Reviews(int page = 1, int pageSize = 36)
        {
            try
            {
                using (var db = new DBContext())
                {
                    // Get promotion news
                    var promotions = db.News.Where(r => r.Type == 1).OrderByDescending(r => r.ReleaseDate);
                    // Paging
                    var pageCount = (promotions.Count() / pageSize) + (promotions.Count() % pageSize > 0 ? 1 : 0);
                    if (page > pageCount)
                    {
                        page = pageCount;
                    }
                    var model = new NewsListViewModel();
                    model.News      = promotions.ToList().ToPagedList <News>(page == 0 ? 1 : page, pageSize);
                    model.PageIndex = page;
                    model.PageSize  = pageSize;

                    // Set meta data
                    ViewBag.MetaDescription = "Memory Audio - Đánh giá sản phẩm";
                    ViewBag.MetaKeywords    = "memory audio,review,danh gia,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd";

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                // Write event logs
                EventLogs.Write("HomeController - Promotion: " + ex.ToString(), EventLogEntryType.Error);

                // Redirect to error page
                return(RedirectToAction("Index", "Error"));
            }
        }
コード例 #10
0
        public NewsListPage()
        {
            var context = new NewsListViewModel
            {
                navigation = Navigation
            };

            BindingContext = context;

            var newsList = new ListView(ListViewCachingStrategy.RecycleElementAndDataTemplate)
            {
                ItemTemplate = new DataTemplate(typeof(NewsListItem)),
                Footer       = new PreloaderListFooter {
                    HeightRequest = NewsListItem.RowHeight
                },
                RowHeight = NewsListItem.RowHeight,
                IsPullToRefreshEnabled = true,
                RefreshCommand         = context.RefreshCommand,
                SelectionMode          = ListViewSelectionMode.None
            };

            newsList.ItemTapped += (sender, e) => {
                if (context.ItemTapped != null)
                {
                    context.ItemTapped.Execute(e.Item);
                }
            };

            newsList.SetBinding(ItemsView <Cell> .ItemsSourceProperty, "News");
            newsList.SetBinding(ListView.IsRefreshingProperty, "IsRefreshing");

            Title   = Constants.NEWS_LISTPAGE_TITLE;
            Content = newsList;
        }
コード例 #11
0
        public ViewResult List(string category)
        {
            string             _category    = category;
            IEnumerable <News> news         = null;
            string             currCategory = "";

            if (string.IsNullOrEmpty(category))
            {
                news = _allNEws.News.OrderBy(i => i.id);
            }
            else
            {
                if (string.Equals("Politics", category, StringComparison.OrdinalIgnoreCase))
                {
                    news = _allNEws.News.Where(i => i.Category.CategoryName.Equals("Политика")).OrderBy(i => i.id);
                }
                else if (string.Equals("Economic", category, StringComparison.OrdinalIgnoreCase))
                {
                    news = _allNEws.News.Where(i => i.Category.CategoryName.Equals("Экономика")).OrderBy(i => i.id);
                }
                currCategory = _category;
            }


            var newsObj = new NewsListViewModel
            {
                AllNews      = news,
                currCategory = currCategory
            };


            ViewBag.Title = "Новостная страница";

            return(View(newsObj));
        }
コード例 #12
0
        // GET : Post
        public ViewResult Index(string id, int page = 1)
        {
            ViewBag.Title = id == "ua" ? "Новини" : "Новости";
            ViewBag.Lang  = id;

            var langId = id == "ua" ? Consts.UaLang : Consts.RuLang;

            NewsListViewModel model = new NewsListViewModel()
            {
                Newses = _repository
                         .NewsCatalog
                         .Select(langId)
                         .OrderByDefault()
                         .Skip((page - 1) * 3)
                         .Take(3),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = Classes.Consts.pageSize,
                    TotalItems   = _repository.NewsCatalog.Select(langId).Count()
                }
            };

            return(View(model));
        }
コード例 #13
0
        async void LoginViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var vm = sender as LoginViewModel;

            switch (e.PropertyName)
            {
            case "LoginRequired":
            {
                if (vm != null && vm.LoginRequired)
                {
                    if (!(MainPage is LoginPage))
                    {
                        MainPage = new LoginPage(vm);
                    }
                }
                else
                {
                    //TODO: Ska avkommenteras när API-anropet går snabbare sen (Gör att news list vyn populeras)
                    NewsListViewModel newsListModel = new NewsListViewModel();
                    await newsListModel.FillNewsList();

                    MasterDetailPage = new MasterDetailPage
                    {
                        Master = new HomeScreenMenuPage(),
                        Detail = new NavigationPage(new HomeScreenPage(newsListModel))          //TODO: Ska ändras till: Detail = new NavigationPage(new HomeScreenPage(news)) sen, se ovan
                    };
                    MainPage = MasterDetailPage;
                }
                break;
            }
            }
        }
コード例 #14
0
        public NewsListViewModel GetNewsListViewModel(int?page, int?pagesize, string category = null)
        {
            int pageIndex = 0;

            if (page > 0)
            {
                pageIndex = page.Value - 1;
            }
            var pageSize = pagesize.GetValueOrDefault(10);

            var pinnedNews = GetAllPinnedNewsByCategory(category);
            var newsCount  = _newsService.GetTotalNewsCount(category);
            var records    = GetManyNewsItemViewModel(category, pageIndex * pageSize, pagesize.GetValueOrDefault(5));

            var list  = new PagedList <NewsItemViewModel>(records, pageIndex, pageSize, newsCount);
            var model = new NewsListViewModel
            {
                CategoryId = category,
                News       = list,
                PinnedNews = pinnedNews,
                PagerModel = new PagerViewModel
                {
                    PageSize     = list.PageSize,
                    TotalRecords = list.TotalCount,
                    PageIndex    = list.PageIndex,
                    RouteValues  = new RouteValues {
                        page = pageIndex, category = category
                    },
                }
            };

            PageExtensions.Pager(model.PagerModel);
            return(model);
        }
コード例 #15
0
        public async Task <IActionResult> NewsList(int?page)
        {
            var allNews = await _newsRepository.GetAllNewsAsync();

            List <NewsListViewModel> newsModel = new List <NewsListViewModel>();

            foreach (var news in allNews)
            {
                var newsList = new NewsListViewModel()
                {
                    Id          = news.Id,
                    CreateDate  = news.CreateDate,
                    ImageName   = news.ImageName,
                    Title       = news.Title,
                    VisitCount  = news.VisitCount,
                    NewsGroupId = news.NewsGroupId
                };
                newsModel.Add(newsList);
            }

            int pageSize   = 5;
            int pageNumber = (page ?? 1);

            return(View(PaginatedList <NewsListViewModel> .Create(newsModel, pageNumber, pageSize)));
        }
コード例 #16
0
        private async void Home_OnClicked(object sender, EventArgs e)
        {
            NewsListViewModel newsListModel = new NewsListViewModel();
            await newsListModel.FillNewsList();

            App.MasterDetailPage.Detail      = new NavigationPage(new HomeScreenPage(newsListModel));
            App.MasterDetailPage.IsPresented = false;
        }
コード例 #17
0
        public ActionResult Index(int page = 1)
        {
            var viewModel = new NewsListViewModel(page);

            //TryUpdateModel(viewModel);
            //return new NewsViewModelActionResult<NewsController>(x => x.Index(page), 1);
            return(View(viewModel));
        }
コード例 #18
0
        public IActionResult NewsSearch(string q)
        {
            var newsListViewModel = new NewsListViewModel()
            {
                News = _newsServices.GetSearchResult(q)
            };

            return(View(newsListViewModel));
        }
コード例 #19
0
        public IActionResult AllNews()
        {
            var newses    = this.newsService.GetAllNewsWithDeleted <NewsViewModel>(1, 1000);
            var viewModel = new NewsListViewModel {
                NewsList = newses, PageNumber = 1, MotorBikeCount = this.newsService.GetCount(), ItemsPerPage = GlobalConstants.ItemsPerPage
            };

            return(this.View(viewModel));
        }
コード例 #20
0
ファイル: NewsService.cs プロジェクト: SCDeveloper66/SC_Api
        public async Task <NewsListViewModel> GetNewsListAsync(string type, string last_id, string language)
        {
            var data = new NewsListViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        new_type = type,
                        last_id  = last_id,
                        emp_id   = userId,
                        lang     = language
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/News/GetNewsList",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter new_type = new SqlParameter("new_type", type ?? "");
                    SqlParameter lastId   = new SqlParameter("last_id", last_id ?? "");
                    SqlParameter emp_id   = new SqlParameter("emp_id", userId ?? "");
                    SqlParameter lang     = new SqlParameter("lang", language ?? "");

                    var spData = context.SpMbNewsList.FromSqlRaw("sp_mb_news_list @new_type, @last_id, @emp_id, @lang", new_type, lastId, emp_id, lang).ToList();
                    data.content = new List <NewscontentViewModel>();
                    foreach (var item in spData)
                    {
                        NewscontentViewModel news = new NewscontentViewModel();
                        news.id           = item.id;
                        news.url_img      = item.url_img;
                        news.title        = item.title;
                        news.sub_detail   = item.sub_detail;
                        news.time         = item.time;
                        news.link_youtube = item.link_youtube;
                        data.content.Add(news);
                    }
                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }
コード例 #21
0
ファイル: HomeController.cs プロジェクト: htastan92/SchoolCMS
        public IActionResult NewsList()
        {
            NewsListViewModel viewModel = new NewsListViewModel
            {
                News = _newsService.GetAllWeb()
            };

            return(View(viewModel));
        }
コード例 #22
0
        public ActionResult News(int?page)
        {
            var model = new NewsListViewModel();

            model.NewsList    = Mapper.Map <IEnumerable <NewsViewModel> >(blService.GetNews(page));
            model.CurrentPage = page ?? 0;

            return(View(model));
        }
コード例 #23
0
ファイル: NewsController.cs プロジェクト: htastan92/SchoolCMS
        public IActionResult Index()
        {
            NewsListViewModel viewModel = new NewsListViewModel()
            {
                News     = _newsService.GetAllAdmin(),
                Statuses = _statusService.GetAll()
            };

            return(View(viewModel));
        }
コード例 #24
0
 public HomeScreenPage(NewsListViewModel newsListViewModel)
 {
     if (newsListViewModel != null)
     {
         _newsListViewModel = newsListViewModel;
     }
     _logger.LoggText("HomeScreenPage");
     InitializeComponent();
     BindingContext = _newsListViewModel;
 }
コード例 #25
0
        public ActionResult Index()
        {
            var model = new NewsListViewModel();

            List <News> newsList = GetLatestFivePosts().Cast <News>().ToList();

            model.NewsList = newsList;

            return(View(model));
        }
コード例 #26
0
        public IActionResult Index(string searchString, int page = 1,
                                   SortState sortOrder           = SortState.DateTimeDesc)
        {
            int pageSize = 3;

            IQueryable <News> source = _newsService.ListAll();

            if (!String.IsNullOrEmpty(searchString))
            {
                source = source.Where(p => p.Title.Contains(searchString) || p.Tags.Contains(searchString) || p.Description.Contains(searchString) || p.NewsText.Contains(searchString) || p.ChatMessages.Any(p => p.Message.Contains(searchString)));
            }

            // сортировка
            switch (sortOrder)
            {
            case SortState.TitleDesc:
                source = source.OrderByDescending(s => s.Title);
                break;

            case SortState.DateTimeAsc:
                source = source.OrderBy(s => s.DateTime);
                break;

            case SortState.DateTimeDesc:
                source = source.OrderByDescending(s => s.DateTime);
                break;

            case SortState.WriterAsc:
                source = source.OrderBy(s => s.Writer.UserName);
                break;

            case SortState.WriterDesc:
                source = source.OrderByDescending(s => s.Writer.UserName);
                break;

            default:
                source = source.OrderBy(s => s.Title);
                break;
            }

            var count = source.Count();
            var items = source.Skip((page - 1) * pageSize).Take(pageSize).ProjectTo <ItemNewsListViewModel>(_mapper.ConfigurationProvider).ToList();

            PageViewModel pageViewModel = new PageViewModel(count, page, pageSize);

            NewsListViewModel newsListViewModel = new NewsListViewModel();

            newsListViewModel.ItemNewsListViewModel = items;
            newsListViewModel.PageViewModel         = pageViewModel;
            newsListViewModel.SortNewsViewModel     = new SortNewsViewModel(sortOrder);
            newsListViewModel.FilterNewsViewModel   = new FilterNewsViewModel(searchString);


            return(View("List", newsListViewModel));
        }
コード例 #27
0
ファイル: NewsBaseController.cs プロジェクト: vits89/Test4Ok
        protected async Task <NewsListViewModel> GetNewsAsync(int?newsSource, bool?orderByDate, int page)
        {
            var pagingInfo = new PagingInfoViewModel
            {
                CurrentPage  = page,
                ItemsPerPage = NEWS_PER_PAGE
            };
            var requestFormData = new RequestFormData
            {
                NewsSource = newsSource
            };

            if (orderByDate.HasValue)
            {
                requestFormData.OrderByDate = orderByDate.Value;
            }

            var newsListViewModel = new NewsListViewModel
            {
                News            = Enumerable.Empty <NewsViewModel>(),
                PagingInfo      = pagingInfo,
                RequestFormData = requestFormData
            };

            if (!(await _dbContext.NewsSources.AnyAsync()))
            {
                return(newsListViewModel);
            }

            var news = _dbContext.News.Include(n => n.NewsSource).AsQueryable();

            if (requestFormData.NewsSource.HasValue)
            {
                if ((await _dbContext.NewsSources.FindAsync(requestFormData.NewsSource.Value)) == null)
                {
                    return(newsListViewModel);
                }

                news = news.Where(n => n.NewsSource.Id == requestFormData.NewsSource.Value);
            }

            pagingInfo.TotalItems = await news.CountAsync();

            news = requestFormData.OrderByDate ?
                   news.OrderByDescending(n => n.PublishDate) :
                   news.OrderBy(n => n.NewsSource.Name);

            news = news.Skip((pagingInfo.CurrentPage - 1) * NEWS_PER_PAGE).Take(NEWS_PER_PAGE);

            newsListViewModel.News = await news.ProjectTo <NewsViewModel>(_mapper.ConfigurationProvider).ToArrayAsync();

            return(newsListViewModel);
        }
コード例 #28
0
        public IActionResult All(int id = 1, int perPage = PostsPerPageDefaultValue)
        {
            var model = new NewsListViewModel
            {
                PageNumber   = id,
                ItemsPerPage = perPage,
                ItemsCount   = this.newsService.GetCount(),
                News         = this.newsService.GetAllInList <NewsInListViewModel>(id, 3),
            };

            return(this.View(model));
        }
コード例 #29
0
        public IActionResult Index()
        {
            var news = this.newsService.GetNews <NewsInListViewModel>();

            var viewModel = new NewsListViewModel
            {
                Count = this.newsService.GetCount(),
                News  = news,
            };

            return(this.View(viewModel));
        }
コード例 #30
0
ファイル: NewsController.cs プロジェクト: phuocpvkqbl/phuoc
        public async Task <ActionResult> Index()
        {
            var news  = (await _newAppService.GetAll(new PagedResultRequestDto {
                MaxResultCount = int.MaxValue
            })).Items;                                                                                                 // Paging not implemented yet
            var model = new NewsListViewModel
            {
                News = news
            };

            return(View(model));
        }