Ejemplo n.º 1
0
        public ActionResult GetNews(GetNewsFilter filter)
        {
            try
            {
                var serviceResponse = newsService.GetAllNews(filter);

                var response = new PagedResponse <NewsViewModel>
                {
                    Data  = Mapper.Map <IEnumerable <NewsViewModel> >(serviceResponse.Data),
                    Total = serviceResponse.Total,
                };

                return(Json(response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(InternalError(ex.Message));
            }
        }
Ejemplo n.º 2
0
        public PagedResponse <News> GetAllNews(GetNewsFilter filter)
        {
            var query = repository
                        .GetAll()
                        .Where(x => x.Language.Id == filter.LanguageId || filter.LanguageId == null)
                        .Where(x => x.Title.Contains(filter.SearchPhrase) || filter.SearchPhrase == null);

            var total = query.Count();

            var news = query
                       .OrderByDescending(x => x.Id)
                       .Skip((filter.Page - 1) * filter.PageSize)
                       .Take(filter.PageSize)
                       .ToList();

            return(new PagedResponse <News>
            {
                Data = news,
                Total = total
            });
        }