public List <NewsResponseDto> GetNews(NewsConditionSearch conditionSearch) { try { if (conditionSearch == null) { conditionSearch = new NewsConditionSearch(); } var paging = new Commons.Paging(db.News.Count(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) , conditionSearch.CurrentPage, conditionSearch.PageSize); var listOfNews = db.News.Where(x => !x.DelFlag && (conditionSearch.KeySearch == null || (conditionSearch.KeySearch != null && (x.Title.Contains(conditionSearch.KeySearch))))) .OrderBy(x => x.Id) .Skip((paging.CurrentPage - 1) * paging.NumberOfRecord) .Take(paging.NumberOfRecord).Select(x => new NewsResponseDto { Id = x.Id, Title = x.Title, ImageUrl = x.ImageUrl, Summary = x.Summary, Content = x.Content, CreatedAt = x.CreatedAt }).ToList(); return(listOfNews == null ? null : listOfNews); } catch (Exception e) { throw e; } }
public IHttpActionResult GetNews([FromBody] NewsConditionSearch conditionSearch) { try { return(Ok(_newsService.GetNews(conditionSearch))); } catch (System.Exception e) { return(InternalServerError(e)); } }